XLib, XTestFakeKeyEvent Latency

I am trying to send a 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 in which I send data and fake char [2] (to convert char from hello [i] to char * for function. This code writes the contents of the greeting to the selected window, but I tried to send 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 doesnโ€™t work, I think this is due to a โ€œdelayโ€ with Xlib, because if I put wait (2) at the end of the โ€œforโ€ loop, it works OK, but I donโ€™t want to wait for 2 seconds every time I send a message.

I do not know how I can do this.

Thanks.

+4
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/1397994/


All Articles