Capturing keyboard events without window focus

Vadim Zeitlin vadim at wxwidgets.org
Sat Jun 2 14:40:07 PDT 2007


On Sat, 2 Jun 2007 15:53:23 -0400 Chris Weiland <hobbiticus at gmail.com> wrote:

CW> It seems as though I can query wxGetKeyState() for my transmit key in order
CW> to accomplish this, but it doesn't quite get me there.  First of all,
CW> wxGetKeyState does not handle toggle buttons like capslock in the same way
CW> as other keys.  It returns true when capslock is on and false when capslock
CW> is off, regardless if the actual key is pressed or not.

 Strangely enough this is done in wxGetKeyState() intentionally (just see
its code). I'm not sure why it was decided to do it like this but it could
be argued that the state of a toggle key is really the state it indicates
and not its current pressed or not state. I guess we should either add a
parameter to wxGetKeyState() telling it whether it should treat the toggle
keys separately or add another function like wxIsKeyPressed() which
wouldn't treat the toggle keys specially.

CW> Second, if I call wxGetKeyState in my recording callback function
CW> (which is the simplest, but perhaps not the best implementation), it
CW> works just fine on windows.  But on linux, I get a line (once) on the
CW> console that says: Xlib: unexpected async reply (sequence 0x948)! and
CW> my program becomes unresponsive.

 Do you call wxGetKeyState() from another thread? If so, don't, it's a GUI
function and so can be called only from the main thread.

CW> So, is there another/better way of doing this within wxWidgets, or will I
CW> have to find another (likely platform-dependent) solution to this?

 Currently there is nothing else but you could try to propose a patch to wx
which would modify it to allow to do what you want. Like this you will be
able to use this code in the next wx version.

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/





More information about the wx-users mailing list