Capturing keyboard events without window focus
Vadim Zeitlin
vadim at wxwidgets.org
Sun Jun 3 14:49:15 PDT 2007
On Sun, 3 Jun 2007 10:41:51 -0400 Chris Weiland <hobbiticus at gmail.com> wrote:
CW> If i'm supposed to call wxGetKeyState from the main thread, where do I do
CW> this? Is there an "OnIdle" function that I can hook into?
OnIdle() function is the name usually called to EVT_IDLE handler.
CW> If so, how often is it called?
If you call event.RequestMore() from the handler, it will be called as
often as possible i.e. your program will consume 100% of CPU which is
probably not good. So you might consider calling wxGetKeyState() after
being notified about key press or release (EVT_KEY_DOWN/UP).
CW> By the way, while I have your attention, I'm having another problem that I
CW> can't seem to solve looking at the docs and you could probably answer pretty
CW> easily. I want to have a "bind key" dialog for choosing which button to set
CW> as the transmit key, which is just a dialog with some text that closes
CW> itself at the first keypress. However, just making an EVT_KEY_DOWN (and/or
CW> EVT_CHAR) event handler on my bind key dialog (inherited from wxDialog) does
CW> not give me any key down events.
Because these events are not propagated upwards the window chain.
CW> As suggested by the docs, I can override ProcessEvent, but I only get
CW> all non-character key events (shift/ctrl/tab, NOT a/b/c/etc). I used
CW> the ProcessEvent found in the richtext example as a template. How do I
CW> get all events?
I don't really understand what do you do but you should be getting EVT_KEY
events for all the keys, you can test this in the text sample.
CW> Also on the subject of keys, is there an easy way to translate a key
CW> code to a human-readable string describing what key it is?
There is a rather roundabout way which consists in creating a
wxAcceleratorEntry for the key and calling its ToString() method. But it's
not especially user-readable (e.g. you'd get names like "KP_HOME" for the
home key on the number pad).
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
More information about the wx-users
mailing list