Original from Rudolf Polzer in dcou.x11.
Added timestamps, flushing of stdout, and usleep to reduce CPU usage.
This commit is contained in:
parent
6899d0d971
commit
1d4e979fba
|
@ -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 $^ $@
|
|
@ -0,0 +1,47 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue