Hi ...
I wanna write a program which distributes keys to the focused
application...
Sadly it doesn't seem to work.
What am i doing wrong?
Maybe someone here has a hint for me.
Ill attach my code to this mail...
thanks
bj0ern
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Command.h>
#include <X11/extensions/XTest.h>
#include <X11/keysymdef.h>
#include <iostream>
#include <unistd.h>
#include <cstdlib>
// Application context
XtAppContext app_context;
// Display structure
Display * disp;
// Structures which holds information about the pressed key
XKeyEvent keyp;
int
main(int argc, char ** argv)
{
Widget toplevel;
toplevel = XtOpenApplication(&app_context, "IrClient",
NULL, 0, &argc, argv, NULL,
applicationShellWidgetClass,
NULL, 0);
disp = XtDisplay(toplevel);
char ** extension_list;
int num_ext;
#if 0
extension_list = XListExtensions(disp, &num_ext);
cout << "Available Extensions:" << endl;
for(; num_ext > 0; --num_ext)
{
cout << "\t- " << extension_list[num_ext - 1] << endl;
}
#endif
Window * win;
int i;
int key_code;
while(1)
{
key_code = XKeysymToKeycode(disp, 0xFF54);
#if 1
Status stat;
keyp.display = disp;
// XGetInputFocus(disp, win, &i);
//keyp.window = *win;
keyp.window = PointerWindow;
keyp.root = DefaultRootWindow(disp);
keyp.subwindow = None;
keyp.time = CurrentTime;
keyp.same_screen = True;
keyp.type = KeyPress;
keyp.keycode = key_code;
stat = XSendEvent(keyp.display, keyp.window, TRUE,
KeyPressMask, (XEvent *)&keyp);
if( ! stat)
{
cout << "Keypress event failed!" << endl;
}
keyp.display = disp;
// XGetInputFocus(disp, win, &i);
// keyp.window = *win;
keyp.window = PointerWindow;
keyp.root = DefaultRootWindow(disp);
keyp.subwindow = None;
keyp.time = CurrentTime;
keyp.same_screen = True;
keyp.type = KeyRelease;
keyp.keycode = key_code;
stat = XSendEvent(keyp.display, keyp.window, TRUE,
KeyReleaseMask, (XEvent *)&keyp);
if( ! stat)
{
cout << "Keyrelease event failed!" << endl;
}
#else
XTestFakeKeyEvent(disp, key_code, True, 0);
// cout << "Send press" << endl;
usleep(100);
XTestFakeKeyEvent(disp, key_code, False, 0);
// cout << "Send release" << endl;
#endif
sleep(1);
}
}