使用pyhook响应组合键(不只是单一的击键)? [英] Using pyhook to respond to key combination (not just single keystrokes)?

查看:1534
本文介绍了使用pyhook响应组合键(不只是单一的击键)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找周围,但我无法找到如何使用pyhook以应对关键的组合如例如<大骨节病>控制 + <大骨节病> C < /骨节病>,而很容易找到如何单键presses如<大骨节病>控制或<大骨节病> 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.

任何帮助AP preciated。

Any help appreciated.

推荐答案

您是否尝试过使用的函数GetKeyState 从HookManager方法?我还没有测试code,但它应该是这样的:

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

下面是函数GetKeyState 进一步的文档一>

Here is further documentation on GetKeyState

这篇关于使用pyhook响应组合键(不只是单一的击键)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆