Created
July 24, 2010 19:33
-
-
Save znz/488911 to your computer and use it in GitHub Desktop.
X11で引数の文字列をキー入力したことにする (http://d.hatena.ne.jp/ku-ma-me/20100724/p1 への入力とか)
This file contains hidden or 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_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