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.