Hello,
I want to have single letter key (i.e. mnemonic and non-RSI inducing)
accelerators, which function if and only if the focus is not in a text control.
(You can create a letter-key accelerator, but then the keypress it is swallowed
before reaching the text control, even if that control has the focus.)
I have seen postings which imply similar desires, but to date, I have found no
way to get such behavior. I was hoping that I could use EVT_CHAR_HOOK to
implement the conditional accelerator, but alas, I am stymied at every turn...
It appears that you cannot get EVT_CHAR_HOOK to fire on letter key events
(at least on wxFrame/Panel/Dialog classes.) There have been numerous
postings and responses about this, e.g.:
Harm Van der Heijden wrote:
I had the exact same problem when I wrote hangman.py a couple of months ago.
The solution was to derive the window that was supposed to capture the key
events from a wxWindow, not from a wxPanel. (wxFrames also don't seem to
react to key events).)
And Robin Dunn wrote in response:
Right, this is because key and char events are not "command events" so the
don't travel up the containment hierarchy but only go to the window where
the event happened.
However, I don't understand this explanation, nor can I get Harm's supposed
workaround to function, e.g.:
Oops, forgot to clarify something. In the frame's init, don't use
EVT_CHAR(self, self.OnChar)
but do something like
wnd = wxWindow(self, -1) # take the whole frame client space by default
EVT_CHAR(wnd, self.OnChar)
(the OnChar *never* fires if I do this. This may be because the frame
contains a panel for laying out controls on, but it doesn't work if I try
the above trick on the panel either.)
But why are only "command events" "hookable?" Why aren't/(can't?) char
events (be) considered commands and "travel up the containment hierarchy?"
Couldn't there be a flag somewhere where you could say you want this
behavior??
Alternatively, is there any way to have an accelerator act conditionally
based on focus?
Any help or solution would be appreciated.
/Will Sadkin
wsadkin@nameconnector.com