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)
"""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 handleEvents(args): # global down # if isinstance(args, MouseEvent): # if args.current_key == 'LButton' and args.event_type == 'key up': # keyboard.press_and_release('ctrl+c') # if isinstance(args, KeyboardEvent): # if 'control' in args.current_key and args.event_type == 'key down': # down = True # if 'control' in args.current_key and args.event_type == 'key up': # down = False # if args.current_key == 'C' and down: # print(1) # def onClipboardChanged() # data = clipboard.mimeData() # if data.hasText(): # print(data.text()) # app = QApplication([]) # clipboard = app.clipboard() # clipboard.dataChanged.connect(onClipboardChanged) if __name__ == '__main__': print('no config.') hk = Hook() hk.handler = handleEvents hk.hook(keyboard=True, mouse=True)
def __main__() -> None: hook = Hook() hook.handler = on_event hook.hook(keyboard=True, mouse=True) hook.listen()
def on_event(args): """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)