在Windows上,如何安装最低级别的全局键盘挂钩?
|
我正在使用Windows上的python开发自定义街机启动器。我想选择系统和游戏,然后启动模拟器-并要求某种组合键才能杀死模拟器。在使用随机应用程序进行测试时,我所有的钥匙挂钩都能正常工作,但是当我实际启动仿真器(例如Nestopia)时,我的钥匙挂钩无法启动。我当前正在使用RegisterHotKey,它获取事件,但不获取热键。任何人都有一个想法,如何安装足够低的东西才能在Nestopia之前实际举行活动?这是我的代码:
import ctypes
import win32con
from ctypes import wintypes
from ctypes import byref
user32 = ctypes.windll.user32
class SimpleKeyboardHook:
def getNextId(self):
SimpleKeyboardHook._id += 1
return SimpleKeyboardHook._id
# modifiers is a bitmask with win32con.[MOD_SHIFT, MOD_ALT, MOD_CONTROL, MOD_WIN]
def waitFor(self, key, modifiers):
# coerce to 0 if necessary
modifiers = modifiers or 0
id = self.getNextId()
hk = user32.RegisterHotKey(None, id, modifiers, key)
print \"register hotkey: \",hk
if not hk:
print \"Unable to register hotkey for key \", key
return False
print \"registered id\", id
try:
msg = wintypes.MSG()
while user32.GetMessageA(byref(msg), None, 0, 0) != 0:
print \"got message\",msg.message,\"which is not\",win32con.WM_HOTKEY
if msg.message == win32con.WM_HOTKEY:
print \"got hotkey\"
if msg.wParam == id:
print \"found proper hotkey\"
return True
user32.TranslateMessage(byref(msg))
user32.DispatchMessageA(byref(msg))
finally:
user32.UnregisterHotKey(None, id)
return False
SimpleKeyboardHook._id = 0
没有找到相关结果
已邀请:
2 个回复
澜悍景哭苟
翱抹村