wxPython: Transferring keyboard events from one frame to another

Z

Ziv Forshtat

Hi All,
I'm in the process of implementing a virtual keypad: I have a wxFrame
which contains a photo the keypad of some device, and I'm using it to
enter special keywords into an editor window (wxStc). Each part of the
photo is associated with a certain keyword, which is sent to the
editor frame and displayed inside the editor. This is working fine.
However, if I want a proper virtual keyboard I should also be able to
transfer the regular keypresses (keyboard events) from my virtual
keypad frame to the editor frame, in order to save the user the
trouble of clicking on the editor window every time in order to set
the focus.

I tried using wxPostEvent to transfer the KEY_DOWN event from the
keypad frame to the appropriate control in the editor frame. The
problem is that the event which I am posting is only caught if I
override the KEY_DOWN event. It does not find its way to the default
event handler of this event.

I have read that there are some problems with wxPostEvent in this
context, but was wondering if someone has found a workaround for this
issue, as this would be the simplest solution for my problem. Other
ideas are also welcome...

BTW, I'm working on MSW.

Thanks,
Ziv
 
J

Josiah Carlson

I'm in the process of implementing a virtual keypad: I have a wxFrame
which contains a photo the keypad of some device, and I'm using it to
enter special keywords into an editor window (wxStc). Each part of the
photo is associated with a certain keyword, which is sent to the
editor frame and displayed inside the editor. This is working fine.
However, if I want a proper virtual keyboard I should also be able to
transfer the regular keypresses (keyboard events) from my virtual
keypad frame to the editor frame, in order to save the user the
trouble of clicking on the editor window every time in order to set
the focus.

Question:
Is your 'virtual keypad' /showing keypresses/, or is your 'virtual
keypad' used for text entry with a mouse?
 
Z

Ziv Forshtat

Josiah Carlson said:
Question:
Is your 'virtual keypad' /showing keypresses/, or is your 'virtual
keypad' used for text entry with a mouse?

Hi Josiah,
My virtual keypad is used for text entry with a mouse, but I also want
to transfer regular keyboard key presses from the keypad to the
'client' window.

Ziv
 
J

Josiah Carlson

Hi Josiah,
My virtual keypad is used for text entry with a mouse, but I also want
to transfer regular keyboard key presses from the keypad to the
'client' window.

If your virtual keypad is a subclass of wxDialog, you're going to have a
problem. wxDialogs eat keypresses if you are not careful, especially 'tab'.

You should instead try to use a plain wxFrame or wxMiniFrame (check the
wxPython demo for code). Then just ignore keyboard events in the keypad
window (using event.Skip()), they should be passed up the parent
heirarchy and get to your main application without much effort. If this
doesn't work for you, here's what I like to do:

#parent frame
def OnKeypress(self, event):
#handle the standard keypress events

#child frame
def OnKeypress(self, event):
self.parent.OnKeyPress(event)


Get that event to the keypress handler, no matter what the cost *wink*.
Another option would be to do the following:

#child frame
def OnKeypress(self, event):
a = event.Copy()
wxPostEvent(self.parent, a)


I hope this helps,
- Josiah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top