The scripts returns (echo
s) xinput id of a pointing device by its name, and if the name is not unique also by its USB interface number.
It is suggested to set the script mode to grant execute permissions.
Name | Position | Mandatory | Default value | Description |
---|---|---|---|---|
DEVICE_NAME |
1 | yes | The device name as reported by xinput list . |
|
DEVICE_NUM |
2 | optional | 0 |
The device USB interface number: udev 's bInterfaceNumber / ID_USB_INTERFACE_NUM value.If the value is one character (digit) only, then it is left padded with 0 . |
flags:-f or --force |
last | optional | absent | If the flag is present, always compare DEVICE_NUM value, even if there is only one device with DEVICE_NAME . |
Both DEVICE_NAME
and DEVICE_NUM
values can be passed either as positional arguments, or in front in the form of environment variables.
0
on success: xinput id is returned.1
otherwise:DEVICE_NAME
is empty or not listed byxinput list
, orDEVICE_NUM
does not match anyudev
'sbInterfaceNumber
/ID_USB_INTERFACE_NUM
value.
mouse_id=$(DEVICE_NAME="Razer Razer DeathAdder V2 X HyperSpeed" ./get_pointer_id.sh)
./get_pointer_id.sh "Razer Razer DeathAdder V2 X HyperSpeed" 1 -f; echo -e "\nExit code: $?"
- The script should also work for keyboard devices if you replace every
pointer
character string withkeyboard
in allbash
/grep
/perl
/awk
/sed
regular expressions, but I have not tested it yet. DEVICE_NAME
(andDEVICE_NUM
) values are stripped, and all whitespace sequences are replace with a single space character (U+0020
: 'str_strip
function invocations.
If you are not sure what the right DEVICE_NUM
value is for your pointing device, follow the instructions:
- Execute
xinput list --short
and note down all you device'sid
values ({device_id}
hereinafter). - For every
{device_id}
, find itsDevice Node
value withxinput --list-props {device_id}
. The outcome should be likeDevice Node (278): "/dev/input/event20"
.
You can also ease it with the following snippet extracted from thename_by_id
function:
xinput --list-props {device_id} | awk 'BEGIN{FS=":[ \t]*"}/^[ \t]*Device Node \(/ {print substr($2, 2, length($2)-2)}'
- Use the
cat
command to open the sysfsDevice Node
file. For example:
cat /dev/input/event20
- Move the mouse, and then terminate
cat
withCtrl+C
. If you could observe some characters being printed out to the terminal, it is very likely you have found correctDevice Node
. Otherwise, please repeat steps2.
,3.
, and4.
for the next{device_id}
value. - Find
Device Node
'sID_USB_INTERFACE_NUM
value withudevadm info --query=property --name={Device Node}
. The outcome should be likeID_USB_INTERFACE_NUM=00
, and these digits are precisely yourDEVICE_NUM
value. If it is00
, then you are good to go with the script's defaultDEVICE_NUM
argument value.
You can also use the following snippet extracted from theis_usb_intfnum_by_id
function:
udevadm info --query=property --name={Device Node} | awk 'BEGIN{FS="="}/^[ \t]*ID_USB_INTERFACE_NUM/ {print $2}'