def listen(): # set up hook hook = Hook() hook.handler = on_event hook.hook(keyboard=True, mouse=True) hook.listen()
def mouse_key_hook(): global monitor_thread_id global hk monitor_thread_id = win32api.GetCurrentThreadId() hk = Hook() hk.handler = on_event hk.hook(keyboard=True, mouse=True)
def __init__(self): self.hook = Hook() self.hook.handler = self.on_event self.HOTKEY = {'Lwin', 'Z'} self.LANGUAGE = "tr-TR" self.recognizer = speech_recognition.Recognizer() self.lock = False self.list_devices()
def setUp(self): """Set some data and ensure the application is in the state we want""" self.hook = Hook() # Save pointers to original system calls before mocking self.CallNextHookEx = windll.user32.CallNextHookEx self.PeekMessageW = windll.user32.PeekMessageW self.TranslateMessage = windll.user32.TranslateMessage self.DispatchMessageW = windll.user32.DispatchMessageW self.atexit_register = atexit.register self.sys_exit = sys.exit self.fake_kbhook_id = 22 self.fake_mousehook_id = 33
def setUp(self): """Set some data and ensure the application is in the state we want""" self.logger = pywinauto.actionlogger.ActionLogger() self.hook = Hook() self.hook.handler = self._on_hook_event self.wait_time = 0.4 self.short_wait_time = self.wait_time / 4.0 self.timer = None self.keybd_events = [] self.mouse_events = [] self.app = None # prevent capturing keyboard keys when launching a test manually time.sleep(self.short_wait_time)
"""Callback for keyboard and mouse events""" if isinstance(args, KeyboardEvent): if args.current_key == 'A' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key: print("Ctrl + A was pressed") if args.current_key == 'K' and args.event_type == 'key down': print("K was pressed") if args.current_key == 'M' and args.event_type == 'key down' and 'U' in args.pressed_key: hk.unhook_mouse() print("Unhook mouse") if args.current_key == 'K' and args.event_type == 'key down' and 'U' in args.pressed_key: hk.unhook_keyboard() print("Unhook keyboard") if isinstance(args, MouseEvent): if args.current_key == 'RButton' and args.event_type == 'key down': print("Right button pressed") if args.current_key == 'WheelButton' and args.event_type == 'key down': print("Wheel button pressed") hk = Hook() hk.handler = on_event main_thread_id = win32api.GetCurrentThreadId() t = Timer(5.0, on_timer) # Quit after 5 seconds t.start() hk.hook(keyboard=True, mouse=True)
def run(self): hk = Hook() hk.handler = self.handleEvents hk.hook(keyboard=True, mouse=True)
def __main__() -> None: hook = Hook() hook.handler = on_event hook.hook(keyboard=True, mouse=True) hook.listen()