You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

#!/usr/bin/env bash
max_speed=20
function handleKeys() {
input_time=$(($(date +%s%N)/1000))
while true; do
end=$(($input_time + 1000000))
inputs=0
while [[ "$input_time" -lt "$end" ]]; do
time_sec=$(od -An -t u8 -N 8)
time_ms=$(od -An -t u8 -N 8)
# Time of the input in usec
input_time=$(($time_ms+$time_sec*1000000))
key_type=$(od -An -t u2 -N 2)
code=$(od -An -t u2 -N 2)
value=$(od -An -t u4 -N 4)
if [[ $key_type -eq 1 ]]; then
if [[ $value -eq 1 ]]; then
inputs=$(($inputs+1))
fi
fi
done
echo "--------------------------------"
echo $inputs over the last second
if [[ $inputs -gt $max_speed ]]; then
if [ -z "$var" ]; then
swaylock -c 000000 -i "./whatthefuckispleadingface.jpg" -s fit
else
# Haven'y actually tested outside of sway but it should work
output=$(mktemp XXXXXXXX.jpg)
convert -resize $(xdpyinfo | grep dimensions | cut -d\ -f7 | cut -dx -f1) "./whatthefuckispleadingface.jpg" "$output"
i3lock -c 000000 -i "$output"
fi
fi
done;
}
sudo cat /dev/input/event0 | handleKeys