Capturing keyboard events without window focus
Chris Weiland
hobbiticus at gmail.com
Mon Jun 4 09:18:08 PDT 2007
Arne, thanks for that file, it's a big help.
Vadim, I don't think the idle event is quite what I want, especially if I
run the risk of using 100% CPU just to get enough granularity. Would
something like a timer work better for this?
By the way, this is what I'm doing to try to capture input events in my bind
key dialog:
BEGIN_EVENT_TABLE(BindKeyDlg, wxDialog)
EVT_KEY_DOWN(BindKeyDlg::OnKeyDown)
EVT_CHAR(BindKeyDlg::OnKeyDown)
END_EVENT_TABLE()
bool BindKeyDlg::ProcessEvent(wxEvent& event)
{
if (event.IsKindOf(CLASSINFO(wxKeyEvent)))
{
OnKeyDown((wxKeyEvent&)event);
return true;
}
return wxDialog::ProcessEvent(event);
}
void BindKeyDlg::OnKeyDown(wxKeyEvent& event)
{
mKeyCode =3D (wxKeyCode)event.GetKeyCode();
if (mKeyCode =3D=3D WXK_ESCAPE)
EndModal(wxID_CANCEL);
EndModal(wxID_OK);
}
I don't think that I should even need the EVT_KEY_DOWN or EVT_CHAR events
handled as long as I am overriding ProcessEvent, but just to figure things
out, I put them in anyway. Also, after testing this on linux, I don't get
any key press events at all. Do I need to add something like a text box
that WILL get key events and hook into that instead? Or am I going the
right direction but have a mistake somewhere?
On 6/3/07, Vadim Zeitlin <vadim at wxwidgets.org> wrote:
>
> 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/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20070604/988=
dfac3/attachment.htm
More information about the wx-users
mailing list