gpt4 book ai didi

python - PyHook 未检测到某些窗口中按下的键

转载 作者:太空狗 更新时间:2023-10-29 17:49:17 25 4
gpt4 key购买 nike

我运行了这个 PyHook 示例代码:

    import pythoncom, pyHook

def OnKeyboardEvent(event):
print 'MessageName:',event.MessageName
print 'Message:',event.Message
print 'Time:',event.Time
print 'Window:',event.Window
print 'WindowName:',event.WindowName
print 'Ascii:', event.Ascii, chr(event.Ascii)
print 'Key:', event.Key
print 'KeyID:', event.KeyID
print 'ScanCode:', event.ScanCode
print 'Extended:', event.Extended
print 'Injected:', event.Injected
print 'Alt', event.Alt
print 'Transition', event.Transition
print '---'

# return True to pass the event to other handlers
return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

尝试一下,它在大多数窗口中都有效,但是当我在游戏窗口中尝试时,它就像我没有按任何东西一样。

有没有办法监听来自特定进程的按键?我该怎么办?

最佳答案

我是从您获得此代码的同一页面上引用的。 Check Here.

If you are using a GUI toolkit (e.g. wxPython), this loop is unnecessary since the toolkit provides its own.

我认为您应该将 pythoncom.PumpMessages() 更改为我不知道是什么的其他内容。

关于python - PyHook 未检测到某些窗口中按下的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33377775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com