From 1d4e979fba5a4c64a0324f3cf0902248e9aa3408 Mon Sep 17 00:00:00 2001 From: hjp Date: Sun, 18 Dec 2005 10:08:52 +0000 Subject: [PATCH] Original from Rudolf Polzer in dcou.x11. Added timestamps, flushing of stdout, and usleep to reduce CPU usage. --- xkeylog/GNUmakefile | 8 ++++++++ xkeylog/xkeylog.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 xkeylog/GNUmakefile create mode 100644 xkeylog/xkeylog.c diff --git a/xkeylog/GNUmakefile b/xkeylog/GNUmakefile new file mode 100644 index 0000000..5bc51d5 --- /dev/null +++ b/xkeylog/GNUmakefile @@ -0,0 +1,8 @@ +all: xkeylog +xkeylog: xkeylog.c + gcc -O xkeylog.c -L/usr/X11R6/lib -lX11 -o xkeylog + +install: /usr/local/bin/xkeylog + +/usr/local/bin/xkeylog: xkeylog + cp $^ $@ diff --git a/xkeylog/xkeylog.c b/xkeylog/xkeylog.c new file mode 100644 index 0000000..e97b3ea --- /dev/null +++ b/xkeylog/xkeylog.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +typedef char Keymap[32]; + +void CompareKeymaps(Display *dpy, const Keymap k1, const Keymap k2) +{ + int i, j; + struct timeval tv; + gettimeofday(&tv, NULL); + for(i = 0; i != 32; ++i) + { + char d = k1[i] &~ k2[i]; + char p = k2[i] &~ k1[i]; + int k; + for(j = 0, k = 1; j != 8; ++j, k <<= 1) + { + if (p & k) { + printf("%d.%06d:p:%d\n", tv.tv_sec, tv.tv_usec, 8*i+j); + } + if (d & k) { + printf("%d.%06d:r:%d\n", tv.tv_sec, tv.tv_usec, 8*i+j); + } + } + } + fflush(stdout); +} + +int main() +{ + Keymap k1 = {0}; + Keymap k2 = {0}; + Display *dpy = XOpenDisplay(0); + if(!dpy) + err(1, "don't have a display, cu\n"); + for(;;) + { + usleep(1000); + XQueryKeymap(dpy, k1); + CompareKeymaps(dpy, k2, k1); + usleep(1000); + XQueryKeymap(dpy, k2); + CompareKeymaps(dpy, k1, k2); + } +}