Re: Getting keyboard state.



Philip Kendall wrote:

On Sat, Jan 13, 2001 at 04:43:26PM +0700, Maxim Koshelev wrote:

Havoc Pennington wrote:


Maintaining the state is much more correct, the get_pointer() solution
is a giant race condition.


Race conditions must be checked only in multithreaded programs where more
than one thread work with gtk...


NO! See Havoc's previous post...

Consider the following situation:

* Key pressed, without shift. Event generated and sent to X server.
* [... time passes whilst your GTK program does complicated processing]
* User finishes pressing key. [...time passes...]. User presses shift.
* [... time passes ... ]
* GTK+ program now reads key event, which was a key being pressed
  _without_ shift. You call get_pointer(...) and get shift being
  pressed. WRONG ANSWER!

Disclaimer:

I probably should've made it clear that keyboard and mouse events already contain information about modifiers, so if you're handling those events you don't need to resort to the get_pointer() trick. It was presented as a solution to the original question as I interpreted it: "how do I get the state of the keyboard *right now*" i.e. not in response to an event. Odds are, you'll never need to do this.

Cheerio,
Tim






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