Here's my first and fifth attempts. The first is decent if you don't need to change the delay. It seems to have some problems with certain key combinations, not sure what was causing it however.
Method 1, in ~/.xbindkeysrc
:
keystate_scrolllock = enable
"xdotool click 1"
Scroll_Lock
Method 5:
keystate_scrolllock = enable
"/home/USER/infinite_clicks.sh event16 KEY_SCROLLLOCK 0.1 &"
Scroll_Lock
With infinite_clicks.sh
being:
#!/bin/bash
kbd=$1 #"event16"
key=$2 #"KEY_SCROLLLOCK"
delay=$3 #"0.1"
fn=`basename "$0"`
if [ $# -le 1 ]; then
echo "Usage: $fn input_device key_name delay"
echo "Example: $fn event16 KEY_SCROLLLOCK 0.1"
echo "Must run as superuser."
exit 1
fi
# do not start if already started
if [[ $(pidof -o %PPID -x $fn) ]]; then
exit 0
fi
while true; do
# this is why you need to use sudo/superuser
evtest --query /dev/input/$kbd EV_KEY $key
# get evtest return code, if it's 0 the key is up
if [[ "$?" -eq "0" ]]; then
break
fi
xdotool click 1 &
sleep "$delay"
done
exit 0
With this code you also need to run xbindkeys as sudo xbindkeys -f ~/.xbindkeysrc
You can find your keyboard event number using sudo evtest
then find the key names using sudo evtest /dev/input/eventXXX
using the event number.