Skip to content

Instantly share code, notes, and snippets.

@znz
Created December 21, 2009 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znz/260841 to your computer and use it in GitHub Desktop.
Save znz/260841 to your computer and use it in GitHub Desktop.
XTEST example
/* 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