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.
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.
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.
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.
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.
XFlush(disp) or XSync(disp, false) after calling XTestFakeKeyEvent?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With