3

I know I can use xinput to disable my mouse and keyboard, and I usually type three commands every time I plug in my keyboard and mouse to my keyboard:

xinput float 'AT Translated Set 2 keyboard'

xinput float 'Ideapad extra buttons'

xinput float 'SynPS Synaptics Touchpad'

I usually use the id values instead of the names but you get what I mean.

So is there any way I can automate it, so whenever my keyboard is plugged in, my computer will run the top two commands, and when my mouse is plugged in, my computer will run the bottom command? Same with re-enabling the devices when my mouse/keyboard is unplugged by running xinput reattach.

2

I never did this, but I will try to help basing on other SE site.

Basically following this answer you should be good to go by modifying udev files and providing scripts:

/etc/udev/rules.d/00-usb-keyboard.rules

ATTRS{idVendor}=="09da", ATTRS{idProduct}=="0260", OWNER="YOURUSERNAME"
ACTION=="add", RUN+="/home/YOURUSERNAME/.bin/usb-keyboard-in_udev"
ACTION=="remove", RUN+="/home/YOURUSERNAME/.bin/usb-keyboard-out_udev"

/home/YOURUSERNAME/.bin/usb-keyboard-in_udev

#!/bin/bash
/home/YOURUSERNAME/.bin/usb-keyboard-in &

#!/bin/bash
sleep 1
DISPLAY=":0.0"
HOME=/home/YOURUSERNAME/
XAUTHORITY=$HOME/.Xauthority
export DISPLAY XAUTHORITY HOME
YOUR_COMMAND_HERE

/home/YOURUSERNAME/.bin/usb-keyboard-out_udev

#!/bin/bash
/home/YOURUSERNAME/.bin/usb-keyboard-out &

/home/YOURUSERNAME/.bin/usb-keyboard-out

#!/bin/bash
sleep 1
DISPLAY=":0.0"
HOME=/home/YOURUSERNAME/
XAUTHORITY=$HOME/.Xauthority
export DISPLAY XAUTHORITY HOME
YOUR_COMMAND_HERE

All these scripts should have executable permission (chmod +x).

According to the answer:

USB keyboard vendor and product ids should be changed as per the output of the command lsusb (For example, my lsusb output have this for my USB Keyboard: Bus 001 Device 006: ID 09da:0260 A4 Tech Co., Ltd)

3
  • Thanks for the link! It worked after using chmod 755 /home/username/.bin/usb-keyboard.* – Randy He Sep 12 '15 at 4:26
  • Do you by any chance know how to do the same with the mouse as well? – Randy He Sep 12 '15 at 4:58
  • Not really - I've never had such problems myself. I just read an answer and tried to show it to you. You might try this question, but I can't guarantee it'll help. – MatthewRock Sep 12 '15 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.