2

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 trigger 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.

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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

1 Comment

That works fine for SINGLE key_up, key_down, or char events, the issue is that it technically has no memory, so after I press and hold the first key_down, if I press a second w/o removing the first, [b]there's no way to re-fire the first key_down[/b] which is the crux of the problem. A single keyEvent cannot handle this, and has no documentation as such.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.