For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > July 2006 > XAutoRepeatOff (Display *)...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XAutoRepeatOff (Display *)...
regis

2006-07-27, 7:00 pm


Greetings,

The two following Xlib functions...

int XAutoRepeatOn (Display *display);
int XAutoRepeatOff(Display *display);

....set on/off the auto-repeat mode of the keyboard on a given display,
i.e., they control whether series of "fake" KeyPress/KeyRelease XEvents
are generated while a key remains physically pressed past some delay.

Is there a way to specify such a thing for one Window only,
and not globally for the whole display ?

If not, when receiving an XKeyEvent,
is there a way to detect if the event is a "fake" one ?
(I hoped testing event.xkey.send_event would do it but no...)

Thanks,

--
regis
regis

2006-07-28, 7:00 pm

regis wrote:

> The two following Xlib functions...
>
> int XAutoRepeatOn (Display *display);
> int XAutoRepeatOff(Display *display);
>
> ...set on/off the auto-repeat mode of the keyboard on a given display,
> i.e., they control whether series of "fake" KeyPress/KeyRelease XEvents
> are generated while a key remains physically pressed past some delay.
>
> Is there a way to specify such a thing for one Window only,
> and not globally for the whole display ?
>
> If not, when receiving an XKeyEvent,
> is there a way to detect if the event is a "fake" one ?
> (I hoped testing event.xkey.send_event would do it but no...)


This ng does not seem to address X programming questions.
Sorry.

However, I found a workaround to detect fake KeyRelease/KeyPress
sequence: the two events always occurs contiguously in the queue
and KeyPress has always its time field set equal to the previous
keyRelease, which seems to never occur otherwise, so:

void
BoundedEventLoop (Display * display, int ignoreAutoRepeat)
{
int k, queued= XEventsQueued (display, QueuedAfterFlush);
XEvent event1, event2;
for (k= 0; k < queued; k++) {
XNextEvent (display, & event1);
if (ignoreAutoRepeat &&
event.xany.type == KeyRelease &&
k+1 < queued &&
XPEvent (display, & event2) &&
event2.xany.type == KeyPress &&
event2.xkey.time == event1.xkey.time) {
/* discard the fake KeyRelease/KeyRelease sequence */
XNextEvent (display, & event2);
k++;
continue;
}
MyEventHandler (display, event1);
}
}

--
regis
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com