Skip to content

Instantly share code, notes, and snippets.

@znz
Created July 24, 2010 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znz/488911 to your computer and use it in GitHub Desktop.
Save znz/488911 to your computer and use it in GitHub Desktop.
X11で引数の文字列をキー入力したことにする (http://d.hatena.ne.jp/ku-ma-me/20100724/p1 への入力とか)
/* gcc -o fake_keys fake_keys.c -lXtst */
/* example usage:
* ./fake_keys "long string you want to input to x11 application"
*/
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <stdio.h>
int
main(int argc, char**argv)
{
Display* dpy;
dpy = XOpenDisplay(NULL);
if (!dpy) {
fprintf(stderr, "Cannot open display.\n");
return 1;
}
if (argc == 2) {
const char *p;
for (p = argv[1]; *p; ++p) {
XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, *p), True, CurrentTime);
XTestFakeKeyEvent(dpy, XKeysymToKeycode(dpy, *p), False, CurrentTime);
}
}
XCloseDisplay(dpy);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment