disabling key auto-repetition
Owen Taylor
otaylor at redhat.com
Sat Jun 3 14:56:03 PDT 2006
On Sat, 2006-06-03 at 22:21 +0200, Roland Plüss wrote:
> hi there, tried to find a place i could ask this question and dropped on
> this mailing list. not sure if this is the right place as something else
> i could not find ( otherwise please redirect me ).
>
> under normal circumstances i receive keys using auto repetition, hence i
> revive a KeyPress and after some time a bunch of KeyRelease/KeyPress
> pairs. so far this is ok, for normal apps. in my app though auto
> repetition really messes up anything so i need to only receive
> KeyPress/KeyRelease for when the user presses and releases a key, not
> repeated in between. i can do this using XAutoRepeatOff/XAutoRepeatOn,
> but this is system wide and if the app for some reason crashes the
> system is fuked up. examining the XKeyEvent structure i could not find
> any hint that would allow me to identify if an event has been send due
> to auto-repetition or due to the user acting on his keyboard. is there a
> way i can detect what messages are due to auto-repeat so i can ignore them?
XkbSetDetectableAutoRepeat (display,
True,
&detectable_autorepeat_supported);
Will change things so your application gets auto-repeat as
press/press/press/../release
On displays that don't support this what GTK+ does is look ahead
in the event queue to see if there is a press with the same timestamp
as a release:
XPeekEvent (xevent->xkey.display, &next_event);
if (next_event.type == KeyPress &&
next_event.xkey.keycode == xevent->xkey.keycode &&
next_event.xkey.time == xevent->xkey.time)
{
/* Ignore the key release event */
}
It's pretty hard for the user to release a key and press it again in 1
millsecond. But XKB and detectable autorepeat will be supported on the
vast majority of current displays.
A thing to note if you watching for key release events is that you will
*not* get a key release event if you lose focus while the user is
holding the key down, so you have to track focus out events as well as
key release events.
Regards,
Owen
More information about the xorg
mailing list