很多时候只是要暂停一下或只想关闭监听,并不想把程序关闭。
但是网上搜了半天,没有找到,然后自己就去翻了翻源码,发现了。
开启监听是:
HookMouse()
和HookKeyboard()
暂停监听是:
UnhookMouse()
和UnhookKeyboard()
给大家展示一下源码:
def HookMouse(self): '''Begins watching for mouse events.''' cpyHook.cSetHook(HookConstants.WH_MOUSE_LL, self.MouseSwitch) self.mouse_hook = True def HookKeyboard(self): '''Begins watching for keyboard events.''' cpyHook.cSetHook(HookConstants.WH_KEYBOARD_LL, self.KeyboardSwitch) self.keyboard_hook = True def UnhookMouse(self): '''Stops watching for mouse events.''' if self.mouse_hook: cpyHook.cUnhook(HookConstants.WH_MOUSE_LL) self.mouse_hook = False def UnhookKeyboard(self): '''Stops watching for keyboard events.''' if self.keyboard_hook: cpyHook.cUnhook(HookConstants.WH_KEYBOARD_LL) self.keyboard_hook = False
喜欢的点个赞❤吧!