小编Joe*_*oel的帖子

在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 …
Run Code Online (Sandbox Code Playgroud)

python windows hook

6
推荐指数
1
解决办法
1685
查看次数

标签 统计

hook ×1

python ×1

windows ×1