Re: losing key release events

On Mon, Mar 18, 2002 at 09:04:38AM -0500, Paul Davis wrote:
> lets imagine that an application is tracking keyboard state in order
> to allow arbitrary key combinations to be used for "shortcuts". when
> the user presses Ctrl-x, the following things happen:
>     key press (Ctrl): mark state as having ctrl pressed
>     key press (x):    mark state as having x pressed
> 	              lookup action for current key state
> 		      execute action
>     key release (x):  remove x from current state			     
>     key release (Ctrl):  remove Ctrl from current state
> consider a situation where a executed action creates a new
> window. imagine that the user has her WM setup to give focus to newly
> created windows. additionally imagine that the new window is a default
> GtkWindow, where key release events are not received.

or alternatively, whilst the user is pressing Ctrl, another window is
created by a separate application, and the WM shifts focus over there. I
think this is a more fundamental problem as we don't have any control
over whether that window receives KeyRelease events or not.

> what happens now is that at least one of the 2 two key release events
> (the Ctrl release) is lost, because it is processed by the X server
> with focus given to the new window which doesn't receive such events.

What I do in my ZX Spectrum emulator[1] (which does something very
similar in order to maintain a state table of which of the Spectrum's
keys are pressed) is simply to clear all keys from the state table when
the main window loses focus.

This works in most cases, but doesn't handle:

* Press Ctrl
* Leave window
* Re-enter window
* Press p

when it thinks p has been pressed rather than Ctrl-p.

[1] if you're really


  Philip Kendall <pak21 srcf ucam org>

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