[wxruby-users] key press event
alex at pressure.to
Tue Jun 16 07:55:12 EDT 2009
Brad Montgomery wrote:
> I got the code to work if I connected the event handler to a Wx::Panel,
> but that will not solve the problem.
> When the event handler is connected to the panel and the user touches
> widget on the screen that widget will now have focus and the panel will
> longer receive the key press events.
By default, only events that are CommandEvents (those associated with
defined actions on controls, like clicking a button, typing text in a
TextCtrl) propagate up the window hierarchy to the parent. Other types
of events, such as MouseEvents and KeyEvents are only received by the
window/widget that currently has focus. So if you have a Panel on top of
a Frame, once the Panel child has had the event, it won't propagate further.
> I need the event handler connected to the Frame/Window and listen for
> even if it does not have focus.
> I am reading from a bar code scanner that sends the data as keyboard
The above normally makes sense for interaction, but I can see it's a bit
inconvenient for this less usual situation. There are various ways you
could work round this. If you have only a single frame receiving data,
and a small number of windows within it, you could capture the key press
event on all of them, and then manipulate the received event's
propagation level with methods like resume_propagation. See this python
If the bar code data is such that it is represented by only a small
number of different possible keys you could try using an
acceleratortable, which directs all key presses within a frame to menu items
More information about the wxruby-users