My laptop keyboard is broke (Esc keeps randomly being pressed, can't fix it), so I've bought a USB keyboard instead. I want to write a script that will run at login which will check if my USB keyboard is connected, and disable my laptop keyboard if so.
I want to use xinput to do this. for background, the correct command to disable device with ID 14 would be:
xinput set-int-prop 14 "Device Enabled" 8 0
I have what I thought was a reliable method of making sure that I am disabling the correct device by listing, grepping, cutting to get the ID number, and then using it in the correct command like so:
xinput --list | egrep "AT Translated" | cut -d "=" -f 2| cut -d "[" -f 1 | xargs -I {} xinput set-int-prop {} "Device Enabled" 8 0
However even this gives a fault:
unable to find device 14
I'm not sure why that is (first question), but I was wondering how I'd go about checking to see if the USB keyboard is there? I need an if function obviously, something which checks if any result is returned when I grep the string "USB USB Keykoard" [yes that spelling is wrong but what appears on my list] from xinput --list
. So my second question is, how do I write that if function?
udev
script? I did so with USB-mouse. – Eddy_Em Feb 14 '13 at 17:22ACTION=="add", SUBSYSTEM=="input", ENV{INPUT_MOUSE}="1", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/eddy/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=1" ACTION=="remove", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}="1", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/eddy/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=0"
– Eddy_Em Feb 14 '13 at 17:47