Created
December 21, 2009 07:49
-
-
Save znz/260841 to your computer and use it in GitHub Desktop.
XTEST example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc -o fake_key fake_key.c -lXtst */ | |
/* example usage: | |
* { sleep 1; ./fake_key l s Return; } & | |
*/ | |
#include <X11/extensions/XTest.h> | |
int | |
main(int argc, char **argv) | |
{ | |
Display *dpy; | |
KeySym sym; | |
KeyCode code; | |
int i; | |
dpy = XOpenDisplay(NULL); | |
if (!dpy) | |
return 1; | |
for (i=1; i<argc; i++) { | |
sym = XStringToKeysym(argv[i]); | |
if (sym == NoSymbol) | |
continue; | |
code = XKeysymToKeycode(dpy, sym); | |
if (code == 0) | |
continue; | |
XTestFakeKeyEvent(dpy, code, True, 0); | |
XTestFakeKeyEvent(dpy, code, False, 0); | |
XFlush(dpy); | |
} | |
XCloseDisplay(dpy); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment