1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
/* xsendkey.c ************************************************/
/*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
char *ProgramName;
Display *dpy;
int scr;
Window win;
unsigned int width, height;
int main(int argc, char **argv)
{
Window ret_win;
int x, y;
unsigned int border_width, depth;
int keycode , is_down=1;
ProgramName = argv[0];
if (argc < 2)
return 1;
/*if (isdigit(argv[1][0]))
printf("%d is a digit\n",argv[1][0]);
*/
keycode = atoi (argv[1]);
if (argc == 3)
is_down = atoi (argv[2]) ? 1 : 0;
dpy = XOpenDisplay("");
if (!dpy) {
fprintf(stderr, "%s: Cannot connect to display ...\n", ProgramName);
return 1;
}
scr = DefaultScreen(dpy);
win = RootWindow(dpy, scr);
XGetGeometry(dpy, win, &ret_win, &x, &y, &width, &height, &border_width, &depth);
fprintf(stderr,"%dx%d keycode %d is_down %d\n", width, height, keycode, is_down);
XTestFakeKeyEvent(dpy, keycode, is_down, 0);
XSync(dpy, 1);
return 0;
}
|