Shell – How to run a shell script on input device event

deviceseventsinputshell-scriptusb

I have a USB remote presenter that appears as a keyboard.

Using evtest I can see the input events from the device.

How can I capture those events in a shell script?

I had see some solutions using C but I would prefer something with only bash if possible.

I already tried something with xbindkeys, but my keyboard events were captured as well and I don't want that.

I also read something about udev rules but seems to me that these rules are only useful for plug and unplug events.

Best Answer

@paulequilibrio thanx to your post I modified your script to get mi IR remote next, prev and stop buttons working with Rhythmbox without lirc in Ubuntu 18.04, this added to the auto run its marvellous...

device='/dev/input/by-id/usb-Formosa21_Beanbag_Emulation_Device_000052F1-event-if00'

#key_playpause='*type 1 (EV_KEY), code 164 (KEY_PLAYPAUSE), value 1*'
key_stop='*type 1 (EV_KEY), code 128 (KEY_STOP), value 1*'
key_next='*type 1 (EV_KEY), code 407 (KEY_NEXT), value 1*'
key_previous='*type 1 (EV_KEY), code 412 (KEY_PREVIOUS), value 1*'

sudo evtest "$device" | while read line; do
    case $line in
#       ($key_playpause)    notify-send "Play/Pause" && rhythmbox-client --playpause ;;
        ($key_stop)     notify-send "Stop" && rhythmbox-client --stop ;;
        ($key_next)     notify-send "Next" && rhythmbox-client --next ;;
        ($key_previous)     notify-send "Previous" && rhythmbox-client --previous ;;
    esac
done
Related Question