Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XLib, XTestFakeKeyEvent latences

Tags:

c++

xlib

I try to send key to an application with XLib and XTestFakeKeyEvent, and it works fine, with the following code :

XSetInputFocus(disp, list[selectWindow],RevertToPointerRoot,CurrentTime);
for(i=0;i<hello.size();i++){
    tamper[0] = hello[i];
    KeySym key = XStringToKeysym(tamper);
    XTestFakeKeyEvent(disp,XKeysymToKeycode(disp, key),True, CurrentTime );
    XTestFakeKeyEvent(disp,XKeysymToKeycode(disp, key),False, CurrentTime );
}

Where Select list[selectWindow] is the window where I send data, and tamper a char[2] (to convert char from hello[i] to char * for the function. This code write the content of the hello wariable into the selected window, but the, I tried to send the Return key,

XSetInputFocus(disp, list[selectWindow],RevertToPointerRoot,CurrentTime);
XTestFakeKeyEvent(disp,XKeysymToKeycode(disp, XK_Return),True, CurrentTime );
XTestFakeKeyEvent(disp,XKeysymToKeycode(disp, XK_Return),False, CurrentTime );

So I select the window again, and send the XK_Return key to the application, but it don't work, I think this is because of a 'lag' with Xlib, because if I put a wait(2) at the end of the 'for' loop,it works fine, but I don't want to wait during 2seconds each time I send a message.

I don't know how I can do to solve that.

Thank you.

like image 536
ex0ns Avatar asked Feb 23 '12 10:02

ex0ns


People also ask

How does XTestFakeKeyEvent work?

If the extension is supported, XTestFakeKeyEvent requests the server to simulate either a KeyPress (if is_press is True) or a KeyRelease (if is_press is False) of the key with the specified keycode; otherwise, the request is ignored.

How does xqueryextension work in Xlib?

The Xlib call XQueryExtension takes one extension name at a time, sends a request to the X server for the id codes for that extension, and waits for a response so it can return those ids to the caller.

How does Xlib look up window properties?

For instance, to lookup a window property, the Xlib code is a single function call: Xlib generates the request to the X server to retrieve the property and appends it to its buffer of requests.

What is the use of Xlib convenience functions?

These convenience functions retrieve specific properties, knowing the details of each property and how to request and decode it. Examples include XGetWMName and XGetWMHints. Some of these functions could be written outside Xlib, but many use Xlib internals in non-trivial ways and are thus inseparable.


1 Answers

XFlush(disp) or XSync(disp, false) after calling XTestFakeKeyEvent?

like image 67
pzanoni Avatar answered Sep 20 '22 06:09

pzanoni