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.

3 Answers 3


@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...


#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 ;;
  • Wellcome to StackExchange, @jorge-guillermo-velez-guajardo . I'm glad to know that I helped you to solve your problem. Oct 1, 2018 at 21:56

@JeffSchaller, thank you for the edits.

Based on @IporSircer's answer (thanks!), I was able to create the following script:


event_blank='*code 48 (KEY_B), value 1*'
event_esc='*code 1 (KEY_ESC), value 1*'
event_f5='*code 63 (KEY_F5), value 1*'
event_prev='*code 104 (KEY_PAGEUP), value 1*'
event_next='*code 109 (KEY_PAGEDOWN), value 1*'

evtest "$device" | while read line; do
  case $line in
    ($event_blank) echo "BLANK SCREEN" ;;
    ($event_f5)    echo "F5" ;;
    ($event_esc)   echo "ESCAPE" ;;
    ($event_prev)  echo "PREVIOUS" ;;
    ($event_next)  echo "NEXT" ;;

Using evtest I was able to find out the event number /dev/input/event18 for the device, but this number may vary depending on the devices on your system and in which order they were connected

Because of that I used udevadm info /dev/input/event18 to find out the device's unique id

S: input/by-id/usb-Targus_Laser_Presentation_Remote-if02-event-kbd

Finally, using evtest again I was able to catch all events from device to use them on the case statement.


This example is monitoring taps on touchpad:

xinput test-xi2 --root "AlpsPS/2 ALPS DualPoint TouchPad" \
| grep --line-buffered "EVENT type 15 (RawButtonPress)"| while read line; do
    paplay --volume 22000 -d $PULSE_SINK $HOME/scripts/data/click.aiff

You can easily modify it for your needs.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .