开发者

How to register multiple KeyEvent triggers in wxPython

I'm currently using wxPython to develop an interactive application; in which, I would like to retain and repeat the last used key pressed. An example of what I'm trying to attain is:

[key 'a' pressed and held][key 'b' pressed and held][key 'b' released][key 'a' released]

aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa

I can't seem to be able to find a way to manually t开发者_开发问答rigger an event like this, I've attempted to use wx.PostEvent, but am either using it incorrectly or it isn't what I'm needing, since technically a key_down event hasn't fired when the second group of 'a's should be registering, and I can't find out how to fire a key_down event with a specific value.


One option in cases like this is to poll the key state yourself in a loop. If key 'a' is pressed then call your action


When you want to catch multi-key events, you have two options. You can catch EVT_CHAR or you can create an Accelerator Table. Here's an article where I attempted to explain how EVT_CHAR works: http://www.blog.pythonlibrary.org/2009/08/29/wxpython-catching-key-and-char-events/

Here's another article on Accelerator Tables: http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/

With the former, you might be able to "record" what was pressed. I don't know why you'd want to do that. I don't think wxPython provides a way to replay keys pressed. On Windows, there's a 3rd party module called SendKeys that you might be able to use for this: http://www.rutherfurd.net/python/sendkeys/

If none of this helps, please ask on the official wxPython mailing list / Google Group. Those guys can probably help you out.


Catch key up/Down events and acts accordingly. http://docs.wxwidgets.org/2.8/wx_wxkeyevent.html http://www.wxpython.org/docs/api/wx.KeyEvent-class.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜