KeyEvent controlled by main window/frame

I'm having difficulty getting the main frame of my application to capture key events when the focus is in child controls (text boxes, etc, -- not other frames). The keypress event simply does not fire unless the frame itself has the focus. I have tab navigation on, but I assume that would only affect the tab key (and turning it off didn't help anyway). I tried turning on WANTS_CHARS, but that didn't help (it didn't seem to affect tab navigation, either, which is good). Even if I add a keypress event procedure to a control and make the only line event.Skip(), the frame still never gets the events. I was under the impression that these events were suppose to bubble up to parent controls, or perhaps pass down to child controls (I'm not sure which), but in any event that the parent frame should be able to intercept a simple alt- or ctl- key combination. Apparently I'm missing something, but I haven't been able to locate it in the documentation. Any help would be greatly appreciated.

Sincerely,
Derek Croxton

Derek Croxton wrote:

I'm having difficulty getting the main frame of my application to capture key events when the focus is in child controls (text boxes, etc, -- not other frames). The keypress event simply does not fire unless the frame itself has the focus. I have tab navigation on, but I assume that would only affect the tab key (and turning it off didn't help anyway). I tried turning on WANTS_CHARS, but that didn't help (it didn't seem to affect tab navigation, either, which is good). Even if I add a keypress event procedure to a control and make the only line event.Skip(), the frame still never gets the events. I was under the impression that these events were suppose to bubble up to parent controls, or perhaps pass down to child controls (I'm not sure which), but in any event that the parent frame should be able to intercept a simple alt- or ctl- key combination. Apparently I'm missing something, but I haven't been able to locate it in the documentation. Any help would be greatly appreciated.

Key and Char events are only sent to the window with the focus, as you have discovered. This is by design.

What you are probably wanting to do is to use an accelerator table and attach it to your frame. Then when the keys in the table are pressed your frame will get an EVT_MENU event (because they are normally used as menu shortcuts.)

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!