How can I know which of the /dev/input/eventX (X=0..7) have the Linux input stream?

后端 未结 5 832
清歌不尽
清歌不尽 2021-01-30 02:00

I am trying to capture linux keyboard/mouse input, and I am reading events from like /dev/input/event2. But it seems the input are sometimes directed to /dev/

5条回答
  •  庸人自扰
    2021-01-30 02:01

    I know it's a little late to reply but I hope this is helpful for friends.

    “mice” contains mouse input data, but to find the file related to the keyboards we need to check the files in folder “by-path”, keyboards file names end with “event-kbd”. We need to find the links to the keyboards, and then we can find the keyboards event file. The following commands can do this automatically for us:

    kbdEvents=($(ls /dev/input/by-path | grep "event-kbd"))     
    for forCounter in "${kbdEvents[@]}"
    do
        eventFile=$(readlink --canonicalize "/dev/input/by-path/${forCounter}")     
        # do anything ...
    done
    

    This code is part of the code for the break time on my personal website : mazKnez.com

提交回复
热议问题