Set global hotkey with Python 2.6

霸气de小男生 提交于 2019-12-29 04:43:06

问题


I wanna setup a global hotkey in python 2.6 that listens to the keyboard shortcut ctrl + D or ctrl+ alt+ D on windows, please help me


回答1:


Tim Golden's python/win32 site is a useful resource for win32 related programming in python. In particular, this example should help:

  • Catch system-wide hotkeys



回答2:


I suggest pyhk. It allows for global wide hotkey registration in python and comes with examples and documentation. Pyhk builds on pyhook.

Hotkey registration is as simple as:

pyhk.addHotkey(SomeHotkey,SomeFunction)



回答3:


The RegisterHotKey method of the wx.Window class is what you're looking for -- as the docs say,

Registers a system wide hotkey. Every time the user presses the hotkey registered here, this window will receive a hotkey event. It will receive the event even if the application is in the background and does not have the input focus because the user is working with some other application. To bind an event handler function to this hotkey use EVT_HOTKEY with an id equal to hotkeyId. Returns True if the hotkey was registered successfully.

So, make an instance of `wx.Window, register the hotkey you want with this method, and possibly do a PushEventHandler if ypu'd rather handle the event(s) in a separate event handler rather than in the window itself (the latter being the default).

Is there anything else in this procedure that is not entirely clear to you...? If so, please edit your question to add whatever further problems you may have!




回答4:


If you want hotkeys in your wxPython program (which I assume you do because of the wxPython tag), then you should use a wx.AcceleratorTable.



来源:https://stackoverflow.com/questions/3337973/set-global-hotkey-with-python-2-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!