2d98967aa7
I rewrote the info-hackspeed script. It should be a tad more energy efficient now (just laptop things), you can also choose between cpm and wpm, and the file is stored in RAM (in /tmp) instead of on disk.
36 lines
965 B
Bash
Executable file
36 lines
965 B
Bash
Executable file
#!/bin/sh
|
|
|
|
# Only count keys that satisfy this condition. $3 is the key index
|
|
# Use `xinput test "AT Translated Set 2 keyboard"` to find out key indices
|
|
CONDITION='($3 >= 24 && $3 <= 33) || ($3 >= 37 && $3 <= 54) || ($3 >= 52 && $3 <= 57)'
|
|
|
|
# cpm: characters per minute
|
|
# wpm: words per minute (1 word = 5 characters)
|
|
METRIC=wpm
|
|
|
|
FORMAT=" %d $METRIC\n"
|
|
|
|
|
|
case "$METRIC" in
|
|
wpm) factor=3; ;;
|
|
cpm) factor=1; ;;
|
|
*) echo "Unsupported metric \"$METRIC\""; exit 1; ;;
|
|
esac
|
|
|
|
hackspeed_cache="$(mktemp -p '' hackspeed_cache.XXXXX)"
|
|
trap 'rm "$hackspeed_cache"' EXIT
|
|
|
|
# Write a dot to our cache for each key press
|
|
printf '' > "$hackspeed_cache"
|
|
xinput test "AT Translated Set 2 keyboard" | \
|
|
stdbuf -o0 awk '$1 == "key" && $2 == "press" && ('"$CONDITION"') {printf "."}' >> "$hackspeed_cache" &
|
|
|
|
while true; do
|
|
lines=$(stat --format %s "$hackspeed_cache")
|
|
value=$(($lines * $factor / 5))
|
|
|
|
printf '' > "$hackspeed_cache"
|
|
printf "$FORMAT" "$value"
|
|
|
|
sleep 20
|
|
done
|