如何在输入设备事件上运行 shell 脚本

pau*_*rio 4 usb input shell-script devices events

我有一个显示为键盘的 USB 远程演示器。

使用evtest我可以看到来自设备的输入事件。

如何在 shell 脚本中捕获这些事件?

我见过一些使用的解决方案C,但我更喜欢仅在bash可能的情况下使用的解决方案。

我已经尝试过一些xbindkeys,但我的键盘事件也被捕获,我不希望这样。

我还阅读了一些内容udev rules,但在我看来,这些规则仅对插入和拔出事件有用。

Jor*_*lez 6

@paulequilibrio 感谢你的帖子,我修改了你的脚本,让 mi IR 远程下一个、上一个和停止按钮在 Ubuntu 18.04 中与没有 lirc 的 Rhythmbox 一起使用,这增加了自动运行的奇妙...

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
Run Code Online (Sandbox Code Playgroud)