fargalaxy1
January 17th, 2012, 12:03 PM
Dear all,
i need to send fake key events to my application, where the keysym to send is readen from a config file and saved to a vector<string>.
I use:
[...]
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/extensions/XTest.h>
#include <unistd.h>
//the below function from http://bharathi.posterous.com/x11-fake-key-event-generation-using-xtest-ext
static void sendKBEvent (Display * display, KeySym keysym, KeySym modsym)
{
KeyCode keycode = 0, modcode = 0;
keycode = XKeysymToKeycode (display, keysym);
if (keycode == 0) return;
XTestGrabControl (display, True);
/* Generate modkey press */
if (modsym != 0)
{
modcode = XKeysymToKeycode(display, modsym);
XTestFakeKeyEvent (display, modcode, True, 0);
}
/* Generate regular key press and release */
XTestFakeKeyEvent (display, keycode, True, 0);
XTestFakeKeyEvent (display, keycode, False, 0);
/* Generate modkey release */
if (modsym != 0)
XTestFakeKeyEvent (display, modcode, False, 0);
XSync (display, False);
XTestGrabControl (display, False);
}
int main(int argc, char** argv)
{
[...]
vector<string> kbdEventsVect;
ConfigFile configFile;
kbdEventsVect = configFile.parseFile("file.txt");
/*kbdEventsVect[] contains XK_Up, XK_Down, XK_Escape, XK_Right*/
[...]
sendKBEvent(display, kbdEventsVect[0], 0);
[...]
}
the problem is that the compiler does not like me passing a string ( kbdEventsVect[0]) to
sendKBEvent(), which instread needs a Keysym var as 2 argument.
error: cannot convert ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘KeySym’ for argument ‘2’ to ‘void sendKBEvent(Display*, KeySym, KeySym)’The wired thing is that if I pass directly the string, everything works fine
sendKBEvent(display, XK_F11, 0); but If I use &kbdEventsVect[0] == XK_F11
sendKBEvent(display, kbdEventsVect[0], 0); I guess i'm missing something...
Thank you for any help you would give me.
Martina
i need to send fake key events to my application, where the keysym to send is readen from a config file and saved to a vector<string>.
I use:
[...]
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/extensions/XTest.h>
#include <unistd.h>
//the below function from http://bharathi.posterous.com/x11-fake-key-event-generation-using-xtest-ext
static void sendKBEvent (Display * display, KeySym keysym, KeySym modsym)
{
KeyCode keycode = 0, modcode = 0;
keycode = XKeysymToKeycode (display, keysym);
if (keycode == 0) return;
XTestGrabControl (display, True);
/* Generate modkey press */
if (modsym != 0)
{
modcode = XKeysymToKeycode(display, modsym);
XTestFakeKeyEvent (display, modcode, True, 0);
}
/* Generate regular key press and release */
XTestFakeKeyEvent (display, keycode, True, 0);
XTestFakeKeyEvent (display, keycode, False, 0);
/* Generate modkey release */
if (modsym != 0)
XTestFakeKeyEvent (display, modcode, False, 0);
XSync (display, False);
XTestGrabControl (display, False);
}
int main(int argc, char** argv)
{
[...]
vector<string> kbdEventsVect;
ConfigFile configFile;
kbdEventsVect = configFile.parseFile("file.txt");
/*kbdEventsVect[] contains XK_Up, XK_Down, XK_Escape, XK_Right*/
[...]
sendKBEvent(display, kbdEventsVect[0], 0);
[...]
}
the problem is that the compiler does not like me passing a string ( kbdEventsVect[0]) to
sendKBEvent(), which instread needs a Keysym var as 2 argument.
error: cannot convert ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘KeySym’ for argument ‘2’ to ‘void sendKBEvent(Display*, KeySym, KeySym)’The wired thing is that if I pass directly the string, everything works fine
sendKBEvent(display, XK_F11, 0); but If I use &kbdEventsVect[0] == XK_F11
sendKBEvent(display, kbdEventsVect[0], 0); I guess i'm missing something...
Thank you for any help you would give me.
Martina