autorepeat problem

Simon Bachmann simonbachmann at
Fri Nov 9 12:02:19 PST 2007

Hi everyone,

I know this has been discussed over and over on this list and other 
places, but I could not find a comprehensive answer to my questions 
Premise: I don't know much about how X works, actually I'd say nothing 
at all...
I'm writing a little game (in Tcl/Tk) and the multiple release/press 
events generated by the autorepeat functionality cause some problems, 
since I need only the "true" keypresses/releases (the physical ones). 
I'd prefer not to simply disable the autorepeat, because in case of a 
crash it might happen that the autorepeat stays turned off.
One often mentioned solution is to compare the timestamp and/or serial 
of two subsequent events. So, to check if a KeyPress event is a "true" 
one, just compare it with the previous release. Pretty simple so far, 
the problem is to check a keyRelease event, since here we have to wait 
some time so an eventual related KeyPress can occur.

Quoting a Qt forum 

"The general, you'll get a keypress VERY soon after the keyrelease when
the key is autorepeating (in terms of X events, the timestamp is
actually identical!)."

My questions here are
a) is the timestamp of a release/press event pair ALWAYS identical when 
autorepeating? can one rely on that?
b) How long is "very soon"? In other words, how long one has to wait 
after a release event before checking for a matching press event? Since 
I plan to store the timestamp/serial of the last KeyPress/Release in a 
variable, I suppose that if the delay is chosen too short, it might 
happen that the comparison might happen between an autorepeat release 
and press. Or are autorepeated release/press generated in a way that 
this just can't happen?
To represent it graphically:


p = press event
r = release event

How long one has to wait after a release event to be _certain_ that the 
comparison of timestamps does not happen at the point indicated with '^'?

Thanks in advance


More information about the xorg mailing list