I am trying to write a bash script that watches the keyboard for specific key presses, and runs commands when it detects them. I am currently able to do this using the input command, but only if the terminal running it is in the foreground. I need to make it work when the window is not in focus.
I have looked at using xinput test-xi2 --root to get each event, which seems to work pretty well, but I am not sure how to effectively convert that input to a key definition that is useful to me.
Here is my current program:
while true; do
read -rsn1 input
if [ "$input" = "a" ];
then
#Do Something
fi
done
The above code works, but only in the foreground.
Any help would be greatly appreciated!