-
Notifications
You must be signed in to change notification settings - Fork 17
/
count-strokes.awk
executable file
·66 lines (59 loc) · 1.59 KB
/
count-strokes.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/awk -f
BEGIN {
FS = " "
current_repeats=1
errors=0
windowchanges=0
mouseevents=0
keyevents=0
unique_keyevents=0
possible_autorepeats=0
uniq_wins=0
}
{
# ASCII 30 octal 036 Record Separator for window focus
if ($0 ~ /^/) {
windowchanges++
winid[$3]++
# ASCII 31 octal 037 Unit Separator for mouse clicks
} else if ($0 ~ /^/) {
is_mouse_key_switch("m")
mouseevents++
} else if ($0 ~ /^$/) {
errors++
} else {
is_mouse_key_switch("k")
keyevents++
if ($0 == lastkey) {
possible_autorepeats++
current_repeats++
if (current_repeats == 2) {
possible_autorepeat_events++
}
} else {
current_repeats=1
unique_keyevents++
}
lastkey=$0
}
}
END {
printf("%s: %d\n", "errors", errors)
printf("%s: %d\n", "mouse_key_switch", mouse_key_switch)
printf("%s: %d\n", "windowchanges", windowchanges)
for (win in winid)
uniq_wins++
printf("%s: %d\n", "uniq_wins", uniq_wins)
printf("%s: %d\n", "mouseevents", mouseevents)
printf("%s: %d\n", "keyevents", keyevents)
printf("%s: %d\n", "unique_keyevents", unique_keyevents)
printf("%s: %d\n", "possible_autorepeat_events", possible_autorepeat_events)
printf("%s: %d\n", "possible_autorepeats", possible_autorepeats)
printf("%s: %d\n", "events", NR - errors)
}
function is_mouse_key_switch(mk) {
if (mouse_key != mk) {
mouse_key_switch++
}
mouse_key = mk
}