// To compile: `gcc -o xkbcat -lX11 xkbcat.c` /* xkbcat Monitors key presses globally across X11. A rather simplified version of `xspy` by Jon A. Maxwell (JAM) as modified for easier physical key monitoring by Antti Korpi . */ /* xspy polls the keyboard to determine the state of all keys on the keyboard. By comparing results it determines which key has been pressed. In this way it echos to the user all physical keys typed. */ #include #include #include #include #include #include char *DEFAULT_DISPLAY = ":0"; const int DEFAULT_DELAY = 10000; #define BIT(c, x) ( c[x/8]& (1<<(x%8)) ) const int KEYSYM_STRLEN = 64; /* Globals */ Display *disp; int printKeyUps = false; char *KeyCodeToStr(int code, int down); int usage() { printf("\ USAGE: xkbcat [-display ] [-delay ] [-up]\n\ display target X display (default %s)\n\ delay polling frequency; microseconds (default %d)\n\ up also print key-ups (default %s)\n", DEFAULT_DISPLAY, DEFAULT_DELAY, (printKeyUps ? "yes" : "no") ); exit(0); } int main(int argc, char *argv[]) { char *hostname = DEFAULT_DISPLAY, *char_ptr, buf1[32], buf2[32], *keys, *saved; int i, delay = DEFAULT_DELAY; /* get args */ for (i=1; i