示例#1
0
 def find_window_regex(self, regex):
     self.main_window = None
     win32gui.EnumWindows(self._window_enum_callback, regex)
示例#2
0
    def __init__(self, title='Progress Dialog', animation_res=161):
        '''
        COMprogressDialog - Windows COM object that shows progress of task.
                            This dialog runs in a separate thread so it can be
                            run from virtually any program without adding
                            threading complexity to that program.

        title         - Dialog window title
        animation_res - animation resource .AVI for interesting
                        progress display

                        animation_res=160 (move)
                        animation_res=161 (copy) [DEFAULT]

        COMprogressDialog.dialog class methods -

          StartProgressDialog(hwndParent, lEnableModeless, dwFlags, pvReserved)
          StopProgressDialog()
          SetTitle(sTitle)
          SetAnimation(hInstAnimation, idAnimation)
          HasUserCancelled()
          SetProgress(completed, total)
          SetProgress64(completed64, total64)
          SetLine(lineNum, sText, lCompactPath, pvReserved)
          SetCancelMsg(sCancelMsg, pvReserved)
          Timer() - Reset timer
          Release() - Close dialog, release resources

        Animation resource in shell32.dll that points to .AVIs

        Written by: Larry Bates (with substantial help from Thomas Heller and
                    Tim Golden on COM interfacing to IProgressDialog),
                    February 2008

                    Updated February 2011 - Added close() method to gracefully
                    close the dialog.
                    
        License: GPL
        Requires: ctypes, comtypes, win32gui
        '''
        LM = "COMprogressDialog.__init__"
        if self._trace:
            print("%s-Entering" % LM)

        #
        # Save title so I can update it with % completed as I progress
        #
        self.title = title
        #
        # Get a list of topWindows
        #
        topWindows = list()
        win32gui.EnumWindows(self._windowEnumerationHandler, topWindows)
        #
        # Isolate Program Manager window from all the other topWindows,
        # this will be used as the parent window for the dialog.
        #
        hwndParent = [w[0] for w in topWindows if w[1] == 'Program Manager'][0]
        import comtypes.client
        try:
            import comtypes.gen.VBProgressDialog

        except ImportError:
            #
            # Create object from the progress tlb file for the COM Progress
            # Dialog
            #
            comtypes.client.GetModule('progdlg.tlb')

        vbpd = comtypes.gen.VBProgressDialog
        #
        # Create instance of progress dialog
        #
        if self._trace:
            print("%s-creating instance of progress dialog" % LM)

        self.dialog = comtypes.client.CreateObject(vbpd.ProgressDialog)
        #
        # Set the animation for the dialog (default=copy) from shell32.dll
        #
        import ctypes
        #
        # Pointer to shell32.dll
        #
        shell32 = ctypes.windll.shell32
        #
        # Get handle for this
        #
        m_hLibShell32 = shell32._handle
        #
        # Set the animation based on animation_res number (default animation
        # is copy animation).
        #
        self.dialog.SetAnimation(m_hLibShell32, animation_res)
        #
        # Insert title into top of dialog
        #
        self.dialog.SetTitle(title)
        #
        # Start the dialog
        #
        self.dialog.StartProgressDialog(hwndParent, None, 0, 0)
        if self._trace:
            print("%s-Leaving" % LM)
        # finding only Chrome's windows. This works for both the browser
        # and content_shell.
        #
        # It seems safest to send the WM_CLOSE messages after discovering
        # all of the sub-process's windows.
        def find_chrome_windows(hwnd, hwnds):
            try:
                _, win_pid = win32process.GetWindowThreadProcessId(hwnd)
                if (pid == win_pid and win32gui.IsWindowVisible(hwnd)
                        and win32gui.IsWindowEnabled(hwnd)
                        and win32gui.GetClassName(hwnd).lower().startswith(
                            app_name)):
                    hwnds.append(hwnd)
            except pywintypes.error, e:
                error_code = e[0]
                # Some windows may close after enumeration and before the calls above,
                # so ignore those.
                if error_code != winerror.ERROR_INVALID_WINDOW_HANDLE:
                    raise
            return True

        hwnds = []
        win32gui.EnumWindows(find_chrome_windows, hwnds)
        if hwnds:
            for hwnd in hwnds:
                win32gui.SendMessage(hwnd, win32con.WM_CLOSE, 0, 0)
            return True
        else:
            logging.info('Did not find any windows owned by target process')
        return False
示例#4
0
def main():
    params = {
        'max_t': 120,
        'relative': 0,
    }
    processArguments(sys.argv[1:], params)

    max_t = params['max_t']

    win_titles = ['Google Chrome']
    try:
        orig_x, orig_y = win32api.GetCursorPos()
        print('GetCursorPos x: {}'.format(orig_x))
        print('GetCursorPos y: {}'.format(orig_y))

        win32gui.EnumWindows(foreach_window, None)

        # for i in range(len(titles)):
        #     print(titles[i])

        target_title = [k[1] for k in titles if all(title in k[1] for title in win_titles)]
        # print('target_title: {}'.format(target_title))

        if not target_title:
            raise IOError('Window with win_titles: {} not found'.format(win_titles))

        target_title = target_title[0]

        target_handle = win32gui.FindWindow(None, target_title)
        rect = win32gui.GetWindowRect(target_handle)

        x = int((rect[0] + rect[2]) / 2)
        y = int((rect[1] + rect[3]) / 2)

        # active_handle = win32gui.GetForegroundWindow()
        # target_title = win32gui.GetWindowText(active_handle)

        print('target_title: {}'.format(target_title))
        print('rect: {}'.format(rect))
        print('x: {}'.format(x))
        print('y: {}'.format(y))

        try:
            app = application.Application().connect(title=target_title, found_index=0)
        except BaseException as e:
            print('Failed to connect to app for window {}: {}'.format(target_title, e))
            exit(0)
        try:
            app_win = app.window(title=target_title)
        except BaseException as e:
            print('Failed to access app window for {}: {}'.format(target_title, e))
            exit(0)

    except BaseException as e:
        print('BaseException: {}'.format(e))
        return

    start_t = time.time()
    while True:
        try:
            app_win.type_keys("{PGDN}")
        except BaseException as e:
            print('BaseException: {}'.format(e))
            break
        end_t = time.time()
        time_elapsed = end_t - start_t
        if time_elapsed > max_t:
            break
        print(time_elapsed)
示例#5
0
def findWindowHandle(name):
    extra = {'name': name, 'matches': []}
    win32gui.EnumWindows(callback, extra)
    return extra
示例#6
0
 def GetAllWindows(self):
     windows = []
     win32gui.EnumWindows(cDesktop.EnumCallback_AllWindows, windows)
     return (windows)
示例#7
0
 def find_window_wildcard(self, wildcard):
     """find a window whose title matches the wildcard regex"""
     self._handle = None
     win32gui.EnumWindows(self._window_enum_callback, wildcard)
示例#8
0
文件: knock.py 项目: TimeFur/knock
 def __init__(self):
     self.open_list = []
     win32gui.EnumWindows(self.winEnumHandler, None)
示例#9
0

# start main function here #
if __name__ == '__main__':
    #freeze_support()

    print "Start!"

    net = get_net(CAFFE_MODE_FILE, DEPLOY_FILE, True)
    transformer = get_transformer(DEPLOY_FILE, MEAN_FILE)

    thread.start_new_thread(PredictThread, ())

    while target_hwnd == None:
        print 'finding target window handler'
        win32gui.EnumWindows(enumHandler, None)
        time.sleep(5)

    # Send key events, works!
    if target_hwnd == None:
        print "No window found!"
        exit()

    # create a hook manager
    hm = pyHook.HookManager()
    # watch for all mouse events
    hm.KeyDown = OnKeyboardEvent
    # set the hook
    hm.HookKeyboard()
    while stop == False:
        pythoncom.PumpWaitingMessages()
示例#10
0
 def enumerate(self, callback, keyword):
     win32gui.EnumWindows(callback, keyword)
示例#11
0
文件: app.py 项目: luoshenseeker/mrfz
    def __init__(self):
        self.game_times = 0  # 游戏回合数
        self.game_hwnd = 0  # 游戏窗口句柄hwnd
        self.game_kind = 1  # 游戏类型 | 1:主线及材料 | 2:剿灭
        self.game_ann_kind = 1  # 剿灭种类
        self.game_title = ""  # 模拟器标题

        self.img_byte_success = base64.b64decode(image_base64.mission_success)
        self.img_success = BytesIO(self.img_byte_success)
        # self.img_success = Image.open(BytesIO(self.img_byte_success))

        self.img_byte_fail = base64.b64decode(image_base64.mission_fail)
        self.img_fail = BytesIO(self.img_byte_fail)
        # self.img_fail = Image.open(BytesIO(self.img_byte_fail))

        self.img_byte_ready = base64.b64decode(image_base64.mission_ready)
        self.img_ready = BytesIO(self.img_byte_ready)
        # self.img_ready = Image.open(BytesIO(self.img_byte_ready))

        self.img_byte_start = base64.b64decode(image_base64.mission_start)
        self.img_start = BytesIO(self.img_byte_start)
        # self.img_start = Image.open(BytesIO(self.img_byte_start))

        self.img_byte_auto_on = base64.b64decode(image_base64.mission_auto_on)
        self.img_auto_on = BytesIO(self.img_byte_auto_on)
        # self.img_on = Image.open(BytesIO(self.img_byte_auto_on))

        self.img_byte_auto_off = base64.b64decode(
            image_base64.mission_auto_off)
        self.img_auto_off = BytesIO(self.img_byte_auto_off)
        # self.img_off = Image.open(BytesIO(self.img_byte_auto_off))

        self.img_byte_playing = base64.b64decode(image_base64.mission_playing)
        self.img_playing = BytesIO(self.img_byte_playing)
        # self.img_playing = Image.open(BytesIO(self.img_byte_playing))
        '''
        self.img_byte_ann_chernob = base64.b64decode(image_base64.ann_chernob)
        self.img_ann_chernob = BytesIO(self.img_byte_ann_chernob)
        # self.img_ann_chernob=Image.open(BytesIO(self.img_byte_ann_chernob))

        self.img_byte_ann_downtown = base64.b64decode(
            image_base64.ann_downtown)
        self.img_ann_downtown = BytesIO(self.img_byte_ann_downtown)
        # self.img_ann_downtown=Image.open(BytesIO(self.img_byte_ann_downtown))

        self.img_byte_ann_outskirts = base64.b64decode(
            image_base64.ann_outskirts)
        self.img_ann_outskirts = BytesIO(self.img_byte_ann_outskirts)
        # self.img_ann_outskirts=Image.open(BytesIO(self.img_byte_ann_outskirts))

        '''
        self.img_byte_ann_success = base64.b64decode(image_base64.ann_success)
        self.img_ann_success = BytesIO(self.img_byte_ann_success)
        # self.imng_ann_success=Image.open(BytesIO(self.img_byte_ann_success))

        self.img_byte_levelup = base64.b64decode(image_base64.level_up)
        self.img_levelup = BytesIO(self.img_byte_levelup)

        self.img_byte_mission_fail_continue = base64.b64decode(
            image_base64.mission_fail_continue)
        self.img_mission_fail_continue = BytesIO(
            self.img_byte_mission_fail_continue)

        self.img_byte_mission_fail_quit = base64.b64decode(
            image_base64.mission_fail_quit)
        self.img_mission_fail_quit = BytesIO(self.img_byte_mission_fail_quit)
        '''
        dict, key为关键词, value为图片的bytes
        list_mainline == 主线及材料关的识别
        list_ann_level == 剿灭的关卡种类,这个并不起作用
        list_ann == 剿灭关的识别
        '''
        self.list_mainline = {
            self.img_ready: "ready",
            self.img_start: "start",
            self.img_playing: "playing",
            self.img_success: "success",
            self.img_fail: "fail",
            self.img_levelup: "levelup",
            self.img_mission_fail_continue: "continue",
            # self.img_mission_fail_quit:"quit"
        }
        '''
        self.list_ann_level = [
            self.img_byte_ann_chernob,
            self.img_byte_ann_downtown,
            self.img_byte_ann_outskirts,
        ]
        '''
        self.list_ann = {
            self.img_ready: "ready",
            self.img_start: "start",
            self.img_playing: "playing",
            self.img_ann_success: "success",
            self.img_levelup: "levelup",
            self.img_mission_fail_continue: "continue",
            # self.img_mission_fail_quit:"quit"
        }
        '''
        hwnd_title为字典,存放当前系统所有的窗口句柄和其标题。
        在网易的mumu模拟器某次更新之后脚本就不起作用了, 
        而雷电模拟器是在主窗口下开了一个子窗口渲染的画面, 通过枚举子窗口就能获得一个可以使用的hwnd
        '''
        self.hwnd_title = dict()

        def getAllHwnd(hwnd, mouse):
            if (win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd)
                    and win32gui.IsWindowVisible(hwnd)):
                self.hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})

        win32gui.EnumWindows(getAllHwnd, 0)
        '''
        正则匹配游戏标题是否包含关键词 "模拟器",
        并将结果存放在game_lists中
        '''

        def setHwnd():
            self.game_lists = []
            for h, t in self.hwnd_title.items():
                if t != "":
                    c = f"{h} {t}"
                    result = re.match(r"([0-9]*) (.*)模拟器(.*)", c, flags=0)
                    if result != None:
                        self.game_lists.append(result)

            if (n := len(self.game_lists)) == 0:
                for h, t in self.hwnd_title.items():
                    if t != "":
                        print(" |", "%-10s" % h, "%.50s" % t)
                print("\n未找到包含'模拟器'字样的游戏进程,请手动指定进程hwnd")
                print("例子: 如您看到[   | 114514   MuMu模拟器   ],请输入114514")
                self.game_hwnd = eval(
                    input("\033[0;30;47m请打开模拟器后重试,或手动输入hwnd(进程名前的数字):\033[0m"))
                self.game_title = self.hwnd_title[self.game_hwnd]

            elif n == 1:
                print("找到了一个可能是模拟器的进程[ ", self.game_lists[0].group(0), " ]")
                case = eval(input("\033[0;30;47m是它吗? 输入1确定,输入0手动指定进程:\033[0m"))
                if case == 1:
                    self.game_title = self.hwnd_title[int(
                        self.game_lists[0].group(1))]
                    self.game_hwnd = self.game_lists[0].group(1)
                elif case == 0:
                    for h, t in self.hwnd_title.items():
                        if t != "":
                            print(" |", "%-10s" % h, "%.50s" % t)
                    self.game_hwnd = eval(
                        input("\033[0;30;47m手动输入hwnd(进程名前的数字):\033[0m"))
                    #self.game_title = self.hwnd_title[self.game_hwnd]
                    self.game_title = ''
示例#12
0
 def list_window_names():
     def winEnumHandler(hwnd, ctx):
         if win32gui.IsWindowVisible(hwnd):
             print(hex(hwnd), win32gui.GetWindowText(hwnd))
     win32gui.EnumWindows(winEnumHandler, None)
示例#13
0
            return window
    else:
        return window


if __name__ == "__main__":
    print("Inicio de programa")
    windowName = " ".join(sys.argv[1:-1])
    key = sys.argv[-1]

    winId = SimpleWindowCheck(windowName)
    # winId = None

    if not (winId):
        windowList = []

        def enumHandler(hwnd, list):
            if windowName in win32gui.GetWindowText(hwnd):
                list.append(hwnd)

        win32gui.EnumWindows(enumHandler, windowList)
        # only the first id, may need to try the others
        winId = windowList[0]

        # can check with this
        for hwnd in windowList:
            hwndChild = win32gui.GetWindow(hwnd, win32con.GW_CHILD)

    win32gui.ShowWindow(winId, win32con.SW_SHOWNORMAL)
    win32gui.SetForegroundWindow(winId)
    sendKey(key)
示例#14
0
 def hide_always_on_top_windows(self):
     win32gui.EnumWindows(self._window_enum_callback_hide, None)
示例#15
0
import sys

import win32api
import win32con
import win32gui
import win32process

# We are going to use the win32gui.EnumWindows() function to get our top level window information.
# This is one of those nasty functions which wants a callback function passed to it (consult the docs if you are really bored).
# So here's one I made earlier:

def windowEnumerationHandler(hwnd, topWindowsHnd):
	if win32gui.IsWindowVisible(hwnd):
		topWindowsHnd.append(hwnd)



# We can pass this, along a list to hold the results, into win32gui.EnumWindows(), as so:

topWindowsHnd = []

win32gui.EnumWindows(windowEnumerationHandler, topWindowsHnd)

sys.stdout.write("Len=%d\n"%len(topWindowsHnd))

for hwnd in topWindowsHnd:
	wnText = win32gui.GetWindowText(hwnd)
	thrId, procId = win32process.GetWindowThreadProcessId(hwnd)
	sys.stdout.write("id=%d %s \n"%(procId,wnText))

示例#16
0
def findWindows():
    win32gui.EnumWindows(_enumW, windows)
    time.sleep(0.5)
    lookharder()
示例#17
0
 def enumProcWnds(pid=None):
     win32gui.EnumWindows(enumWindowsProc, pid)
示例#18
0
def handle_notice(trade_hwnd, stock_code, price, lot):
    # 获取 desktop 句柄
    # desktop = win32gui.GetDesktopWindow()

    # 获取所有 提示信息 或 委托确认 弹出窗的句柄
    # 两者的共同特征是
    #       父句柄 是 #32769 Desktop 主窗口,pywin32 GetParent 函数获取的不是父窗口的句柄
    #       owner 句柄是 交易窗口主句柄
    # 根据 弹出窗口大小判断更快,所以按大小判断
    def call_back(handle, dialog_l):
        _left, _top, _right, _bottom = win32gui.GetWindowRect(handle)
        # (_right - _left == 300) and (_bottom - _top == 195)
        # print(win32gui.GetParent(handle))
        if win32gui.GetClassName(handle) == "#32770" and win32gui.GetWindow(handle, win32con.GW_OWNER) == trade_hwnd:
            if (_right - _left == 300) and (_bottom - _top == 195):
                dialog_l.append(handle)
            elif (_right - _left == 345) and (_bottom - _top == 229):
                dialog_l.append(handle)

    """ 下单 时的提示信息 """
    while True:
        dialog_list = []
        win32gui.EnumWindows(call_back, dialog_list)
        # 获得 每个 dialog 句柄的子句柄,判断出是 提示信息 或 委托确认 弹出窗
        notice_list = []
        confirm_list = []
        for dialog in dialog_list:
            li = []
            win32gui.EnumChildWindows(dialog, lambda handle, param: param.append(handle), li)
            for l in li:
                txt = win32gui.GetWindowText(l)
                if txt == "提示信息":
                    notice_list.append(dialog)
                elif txt == "委托确认":
                    confirm_list.append(dialog)

        if len(notice_list) > 1 or len(confirm_list) > 1:
            exit(-1)
        # 如果没有提示信息窗口,而存在委托窗口,判断无误下单后 退出
        if len(confirm_list) == 1 and len(notice_list) == 0:
            # 确认委托 或 取消委托 后退出
            confirm = confirm_list[0]
            confirm_info = {}
            confirm_son = []
            win32gui.EnumChildWindows(confirm, lambda handle, param: param.append(handle), confirm_son)
            for son in confirm_son:
                txt = win32gui.GetWindowText(son)
                # print(txt)
                cls = win32gui.GetClassName(son)
                left, top, right, bottom = win32gui.GetWindowRect(son)
                if cls == "Static" and right - left == 227:
                    confirm_info.update(info=txt)
                elif txt == "是(&Y)":
                    confirm_info.update(yes_btn=son)
                elif txt == "否(&N)":
                    confirm_info.update(no_btn=son)

            if stock_code in confirm_info["info"] and str(price) in confirm_info["info"] \
                    and str(lot * 100) in confirm_info["info"]:
                win32api.PostMessage(confirm_info["yes_btn"], win32con.WM_LBUTTONDOWN, None, None)
                win32api.PostMessage(confirm_info["yes_btn"], win32con.WM_LBUTTONUP, None, None)
            else:
                win32api.PostMessage(confirm_info["no_btn"], win32con.WM_LBUTTONDOWN, None, None)
                win32api.PostMessage(confirm_info["no_btn"], win32con.WM_LBUTTONUP, None, None)
            return "成功"

        # 如果当前只存在 提示信息窗口
        if len(notice_list) == 1:
            notice = notice_list[0]
            notice_info = {}
            notice_son = []
            win32gui.EnumChildWindows(notice, lambda handle, param: param.append(handle), notice_son)
            for son in notice_son:
                txt = win32gui.GetWindowText(son)
                cls = win32gui.GetClassName(son)
                left, top, right, bottom = win32gui.GetWindowRect(son)
                if cls == "Static" and right - left == 300:
                    notice_info.update(info=txt)
                elif txt == "是(&Y)":
                    notice_info.update(yes_btn=son)
                elif txt == "否(&N)":
                    notice_info.update(no_btn=son)

            # 提示信息弹出框 发送取消 后,直接退出
            if "超出涨跌停限制" in notice_info["info"]:
                win32api.PostMessage(notice_info["no_btn"], win32con.WM_LBUTTONDOWN, None, None)
                win32api.PostMessage(notice_info["no_btn"], win32con.WM_LBUTTONUP, None, None)
                return
示例#19
0
文件: test.py 项目: gurgen16/WindowsP
import win32gui


def testo(hw, ok):
    print(hw)


yo = ''
win32gui.EnumWindows(testo, yo)
示例#20
0
文件: app.py 项目: g5fighter/AdMuted
def getWindowName():
    if hownd == "":
        win32gui.EnumWindows(winEnumHandler, None)
    else:
        winEnumHandler(hownd, None)
示例#21
0
        print("Game client not open.")
    else:
        send_input_hax(client_hwnd[0], "啊啊啊")


def have_fun():
    # url = "https://nmsl.shadiao.app/api.php?lang=zh_cn"
    # res = requests.get(url).text
    send_input_hax(client_hwnd[0], "啊啊啊")


def callback(hwnd, client_hwnd):
    if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
        print(win32gui.GetWindowText(hwnd))
        print(hwnd)
        if win32gui.GetWindowText(hwnd).find(
                'League of Legends (TM) Client') != -1:
            client_hwnd.append(hwnd)
        if win32gui.GetWindowText(hwnd).find("QQ") != -1:
            print("bbbb")
            client_hwnd.append(hwnd)
        #client_hwnd.append(win32gui.GetWindowText(hwnd))


if __name__ == '__main__':
    hotkey = Hotkey()
    hotkey.start()
    client_hwnd = []
    win32gui.EnumWindows(callback, client_hwnd)
    fn = hotkey.callback(0, have_fun)
    thread_it(fn)
示例#22
0
# C.run()
#
# class TapRecord(PyKeyboardEvent):
#     def __init__(self):
#         PyKeyboardEvent.__init__(self)
#
#     def tap(self, keycode, character, press):
#         print(time.time(), keycode, character, press)
#
# t = TapRecord()
# t.run()
# #这些对象是一个架构用于监听鼠标和键盘的输入;他们除了监听之外不会做任何事,需要继承重构他们#PyKeyboardEvent为编写完成,所以这里是一个继承PyMouseEvent的例子:


def get_all_hwnd(hwnd, mouse):
    if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(
            hwnd) and win32gui.IsWindowVisible(hwnd):
        hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})


def press(key):
    key = key[0]


if __name__ in "__main__":
    win32gui.EnumWindows(get_all_hwnd, 0)
    for h, t in hwnd_title.items():
        if t is not "":
            print(h, t)
# 9701852
示例#23
0
            global rect
            rect = win32gui.GetWindowRect(hwnd)
        return

    os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (0, 0)
    pygame.init()
    screen = pygame.display.set_mode([300, 150])
    textSurfaceObj = pygame.font.Font(
        'meaningless_data/font/OpenSans-Bold.ttf',
        32).render('loading...', True, (255, 255, 255), (0, 0, 0))
    textRectObj = textSurfaceObj.get_rect()
    textRectObj.center = (100, 30)
    screen.blit(textSurfaceObj, textRectObj)
    pygame.display.set_caption("meaningless: test")
    pygame.display.flip()
    win32gui.EnumWindows(getWinPos, None)
    pygame.quit()

    meaningless_shoot.windowPos_x_c = -rect[0]
    meaningless_shoot.windowPos_y_c = -rect[1]
except:
    meaningless_shoot.windowPos_x_c = 10
    meaningless_shoot.windowPos_y_c = 35


class initApp(QWidget):
    def __init__(self):
        super().__init__()
        self.game_start = False
        self.initUI()
示例#24
0
def get_all_win_by_name(name):
	win32gui.EnumWindows(get_all_hwnd_title, 0)
	name_list = [t for h, t in hwnd_title.items()]
	name_list_filter = list(filter(lambda x: name in x, name_list))

	return name_list_filter
示例#25
0
HWND_TOP = 0
HWND_TOPMOST = -1
SWP_HIDEWINDOW = 0x0080
SWP_NOREDRAW = 0x0008
SWP_SHOWWINDOW = 0x0040
SWP_NOMOVE = 0x0002
SWP_NOSIZE = 0x0001
GW_HWNDNEXT = 2

## -------------------------------------
## 現在アクティブなウィンドウ名を探す
## -------------------------------------
process_list = []
def callback(handle, _):
    process_list.append(win32gui.GetWindowText(handle))
win32gui.EnumWindows(callback, None)


## -------------------------------------
## 対象ウィンドウを設定
## -------------------------------------
hnd = win32gui.GetDesktopWindow()
if process_list:
    for process_name in process_list:
        if sc_file_name in process_name:
            hSelfWnd = win32gui.FindWindow(None, process_name)
            hNextWnd = win32gui.GetWindow(hSelfWnd, GW_HWNDNEXT)
            win32gui.SetWindowPos(hSelfWnd, HWND_BOTTOM, 0, 0, 0, 0, (SWP_HIDEWINDOW))
            win32gui.SetWindowPos(hNextWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
            win32gui.BringWindowToTop(hNextWnd)
            hnd = win32gui.GetForegroundWindow()
示例#26
0
import pyautogui
import time
import random
import win32gui


def handler(hwnd, windows):
    windows.append((hwnd, win32gui.GetWindowText(hwnd)))


all_windows = []
wow_windows = []
win32gui.EnumWindows(handler, all_windows)
for i in all_windows:
    if "魔兽世界" in i[1]:
        wow_windows.append(i[0])


def switch_to_window(hwnd):
    win32gui.ShowWindow(hwnd, 5)  # SW_SHOW
    win32gui.SetForegroundWindow(hwnd)


def logout_login():
    pyautogui.press('esc')
    time.sleep(5)
    pyautogui.click(960, 618)
    time.sleep(30)
    pyautogui.click(960, 988)
    time.sleep(30)
    def item_click_response(self, item):
        if self.combo_box_item_click_response.currentText() == '编辑':
            if item.parent():
                group_list = [gp for gp in self.get_database_dict()]
                old_content = (item.parent().text(0), item.text(0),
                               item.text(1))
                dialog = EditContentDialog(self, group_list, old_content)
                return_signal = dialog.exec_()
                if return_signal == QDialog.Accepted:
                    if old_content != dialog.add_content:
                        old_group, old_key, old_content = old_content
                        group, key, content = dialog.add_content
                        self.db_cursor.execute(
                            '''UPDATE CLIPBOARD SET CONTENT_GROUP = \'%s\', 
                            KEY = \'%s\', CONTENT = \'%s\' 
                            WHERE CONTENT_GROUP = \'%s\' AND 
                            KEY = \'%s\' AND 
                            CONTENT = \'%s\'''' %
                            (group, key, content, old_group, old_key,
                             old_content))
                        self.db_conn.commit()
                        self.display_clip_board_database()
        elif self.combo_box_item_click_response.currentText() == '复制':
            if item.parent():
                self.clip_board.setText(item.text(1))
        elif self.combo_box_item_click_response.currentText() == '复制并粘贴':
            if item.parent():
                self.clip_board.setText(item.text(1))
                focus_win_hwnd = xx = win32gui.GetFocus()
                hwnd_title = dict()

                def get_all_window(hwnd, mouse):

                    if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and\
                            win32gui.IsWindowVisible(hwnd):
                        hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})

                win32gui.EnumWindows(get_all_window, 1)
                if hwnd_title:
                    hwnd_list = [h for h, t in hwnd_title.items()]
                    index = hwnd_list.index(focus_win_hwnd)
                    if self.is_top:
                        if index < len(hwnd_list) - 2:
                            focus_win_hwnd = hwnd_list[index + 2]
                            win32gui.SetForegroundWindow(focus_win_hwnd)
                            win32api.keybd_event(17, 0, 0, 0)
                            win32api.keybd_event(86, 0, 0, 0)
                            win32api.keybd_event(86, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(17, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(13, 0, 0, 0)
                            win32api.keybd_event(13, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                    else:
                        if index < len(hwnd_list) - 1:
                            focus_win_hwnd = hwnd_list[index + 1]
                            win32gui.SetForegroundWindow(focus_win_hwnd)
                            win32api.keybd_event(17, 0, 0, 0)
                            win32api.keybd_event(86, 0, 0, 0)
                            win32api.keybd_event(86, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(17, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
                            win32api.keybd_event(13, 0, 0, 0)
                            win32api.keybd_event(13, 0,
                                                 win32con.KEYEVENTF_KEYUP, 0)
        else:
            pass
示例#28
0
 def find_window_wildcard(self, wildcard):
     self._handle = None
     win32gui.EnumWindows(self._window_enum_callback, wildcard)
示例#29
0
 def getWindowTitle(self):
     win32gui.EnumWindows(self.enumWindowsProc, self.PID)
     return self.windowTitle
示例#30
0
 def _getWindowList(self):
     """清空原来的列表"""
     self.windowList.clear()
     win32gui.EnumWindows(self._enumWindows, None)