Re: Getting keyboard state.



Maxim Koshelev <chuchelo krasu ru> writes:
Does somebody know how to get state of the keyboard via gtk/gdk?
I just need to know about current state of Shift key in my program.


Try gdk_window_get_pointer(), pass in NULL for x and y if you don't
care about them.

This is a really good way to get race conditions though; if you're
currently processing an event and ask for the state, the event you're
processing could have occurred a really long, user-perceptible amount
of time before the state you get back from gdk_window_get_pointer().

e.g. if you are processing a press of the "K" key, and ask for the
state, and Shift is held, then Shift could have been pressed many
seconds after "K" was pressed. So it would be wrong to pretend there
was a "Shift-K."

So try really hard to instead use the last state received in an event,
key/button/motion events have a state field.

Havoc





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]