disabling key auto-repetition
Roland Plüss
roland at rptd.dnsalias.net
Sat Jun 3 16:28:00 PDT 2006
Owen Taylor wrote:
> 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.
>
sounds like a plan. i'll try that out.
> 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.
>
it's for a game engine project so the user is usually not expected to
tab out of the application often and if he does he has anyways to press
the key again to either start again his action or unblock it. hence this
should be not that much of a problem right now.
you said not all displays do support it. how can i check that the
display does support the xbk thingy?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
URL: <http://lists.x.org/archives/xorg/attachments/20060604/b35e78ae/attachment.pgp>
More information about the xorg
mailing list