使用 pyhook 响应组合键(不仅仅是单次击键)? [英] Using pyhook to respond to key combination (not just single keystrokes)?
本文介绍了使用 pyhook 响应组合键(不仅仅是单次击键)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在环顾四周,但找不到如何使用 pyhook 响应键 组合 的示例,例如 Ctrl + C 而很容易找到如何分别响应单个按键的示例,例如 Ctrl 或 C.
I've been looking around but I can't find an example of how to use pyhook to respond to key combinations such as Ctrl + C whereas it is easy to find examples of how to respond to single keypresses such as Ctrl or C separately.
顺便说一句,我说的是 Windows XP 上的 Python 2.6.
BTW, I'm talking about Python 2.6 on Windows XP.
感谢任何帮助.
推荐答案
您是否尝试过使用 GetKeyState 方法来自 HookManager?我还没有测试过代码,但它应该是这样的:
Have you tried to use the GetKeyState method from HookManager? I haven't tested the code but it should be something like this:
from pyHook import HookManager
from pyHook.HookManager import HookConstants
def OnKeyboardEvent(event):
ctrl_pressed = HookManager.GetKeyState(HookConstants.VKeyToID('VK_CONTROL') >> 15)
if ctrl_pressed and HookConstant.IDToName(event.keyId) == 'c':
# process ctrl-c
这篇关于使用 pyhook 响应组合键(不仅仅是单次击键)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文