Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python活动窗口记录器_Python_Pywin32 - Fatal编程技术网

Python活动窗口记录器

Python活动窗口记录器,python,pywin32,Python,Pywin32,如何使用python将用户输入记录在活动窗口中,例如“example\u window\u name”?我可以使用以下方法获得活动窗口: from win32gui import GetWindowText, GetForegroundWindow print GetWindowText(GetForegroundWindow()) 但是,我如何开始枚举窗口,直到“example\u window\u name”成为活动窗口,然后开始记录用户在“example\u window\u name”

如何使用python将用户输入记录在活动窗口中,例如“example\u window\u name”?我可以使用以下方法获得活动窗口:

from win32gui import GetWindowText, GetForegroundWindow
print GetWindowText(GetForegroundWindow())
但是,我如何开始枚举窗口,直到“example\u window\u name”成为活动窗口,然后开始记录用户在“example\u window\u name”中输入的击键,直到它变为非活动状态。 到目前为止,我得到的是:

import win32gui
import re

class WindowMgr:
"""Encapsulates some calls to the winapi for window management"""
def __init__ (self):
    """Constructor"""
    self._handle = None

def find_window(self, class_name, window_name = None):
    """find a window by its class_name"""
    self._handle = win32gui.FindWindow(class_name, window_name)

def _window_enum_callback(self, hwnd, wildcard):
    '''Pass to win32gui.EnumWindows() to check all the opened windows'''
    if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) != None:
        self._handle = hwnd

def find_window_wildcard(self, wildcard):
    self._handle = None
    win32gui.EnumWindows(self._window_enum_callback, wildcard)

def set_foreground(self):
    """put the window in the foreground"""
    win32gui.SetForegroundWindow(self._handle)

w = WindowMgr()
w.find_window_wildcard(".*Hello.*")
w.set_foreground()
谢谢你的帮助