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.