samedi 24 février 2018

When sending an XKeyEvent with XSendEvent, the system doesn't respond the first time, then responds on XCloseDisplay

I've got the code:

// Send a fake key press event to the window.
XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, XKeysymToKeycode(display, key), modifier);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);


// Send a fake key release event to the window.
event = createKeyEvent(display, winFocus, winRoot, false, XKeysymToKeycode(display, key), modifier);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);

Which to my understanding sends a keyboard event to the system, first the press then the release. This works, however the first event does not happen, but when the program ends it sends another event. My theory is that it's delaying the events by one? Is there some buffer it's being kept in once sent that needs flushing?

So for example I simulate pressing the a key 5 times, it types a 4 times then when XCloseDisplay is called it types the 5th. When putting a delay between each press it's the first that doesn't appear.

Thanks in advance for the help. I can provide more detail on the surrounding code if needed.

Aucun commentaire:

Enregistrer un commentaire