Ubuntu: Script to disable mouse and keyboard


I would like to create a script for my computer that let's me render it unusable for a set amount of minutes. I would like that I can have a script that when run will kill all my keyboard and mouse drivers so that I can't operate it.

Furthermore I would like it to ignore anything I plug in so that I can not just unplug and plug my keyboard and mouse or anything else.

If you have any idea on how I could implement such a thing.


First, run xinput -list to get the ID of your mouse and keyboard. The output should look like this:

⎡ Virtual core pointer                      id=2    [master pointer  (3)]  ⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]  ⎜   ↳ HID 413c:3010                             id=8    [slave  pointer  (2)]  ⎣ Virtual core keyboard                     id=3    [master keyboard (2)]      ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]      ↳ Power Button                              id=6    [slave  keyboard (3)]      ↳ Power Button                              id=7    [slave  keyboard (3)]      ↳ Eee PC WMI hotkeys                        id=9    [slave  keyboard (3)]      ↳ AT Translated Set 2 keyboard              id=10   [slave  keyboard (3)]  

In my case, my keyboard's ID is 10, and my mouse's ID is 8

Then, you can run this command, replacing the 8 and 10 with your keyboard and mouse's IDs. The amount of time that they will be disabled for in seconds is the number after sleep

xinput set-prop 8 'Device Enabled' 0 ; xinput set-prop 10 'Device Enabled' 0 ; sleep 5 ; xinput set-prop 8 'Device Enabled' 1 ; xinput set-prop 10 'Device Enabled' 1  


To prevent another mouse or keyboard plugged into another USB port from working, the best solution I have is to unload the USB HID kernel module.

sudo -i  rmmod usbhid ; sleep 5 ; modprobe usbhid  

(Again, replace 5 with the desired inoperable time in seconds)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »