Code for the most part comes from: http://unix.stackexchange.com/questions/129159/record-every-keystroke-and-store-in-a-file
I added the timestamp with hires timing. Log as CSV.
- Time::HiRes
- perl
- xmodmap
- xinput
Code for the most part comes from: http://unix.stackexchange.com/questions/129159/record-every-keystroke-and-store-in-a-file
I added the timestamp with hires timing. Log as CSV.
#!/bin/bash | |
xinput test-xi2 --root | perl -MTime::HiRes=time -lne ' | |
BEGIN{$"=","; | |
select((select(STDOUT),$|=1)[0]); | |
open X, "-|", "xmodmap -pke"; | |
while (<X>) {$k{$1}=$2 if /^keycode\s+(\d+) = (\w+)/} | |
open X, "-|", "xmodmap -pm"; <X>;<X>; | |
while (<X>) {if (/^(\w+)\s+(\w*)/){($k=$2)=~s/_[LR]$//;$m[$i++]=$k||$1}} | |
close X; | |
} | |
$time = time(); | |
if (/^EVENT type.*\((.*)\)/) {$e = $1} | |
elsif (/detail: (\d+)/) {$d=$1} | |
elsif (/modifiers:.*effective: (.*)/) { | |
$m=$1; | |
if ($e =~ /^Key/){ | |
my @mods; | |
for (0..$#m) {push @mods, $m[$_] if (hex($m) & (1<<$_))} | |
print "$time,$e,$d,$k{$d},$m,@mods" | |
} | |
}' |