Skip to content

Instantly share code, notes, and snippets.

@diego09310
Created April 29, 2018 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diego09310/5d4bddb9736e6506b20cd1528a72e200 to your computer and use it in GitHub Desktop.
Save diego09310/5d4bddb9736e6506b20cd1528a72e200 to your computer and use it in GitHub Desktop.
Disable input devices in Linux
#!/bin/bash
#
# Shell script to disable (and reenable) the keyboard and the touchpad.
# I use it when cats are around and I can work with a wireless keyboard/mouse.
# To use it, execute "xinput list" to print the list of input devices and add
# the id and the master it belongs (number in parenthesis) to the id and
# master arrays.
# "./cat_mode.sh [on]" disables the configured devices
# "./cat_mode.sh off" (off or anything else) reenables the devices
#
id=(6 15 16)
master=(3 3 2)
idLength=${#id[@]}
if [ $# -eq 1 ]; then
input=$1
else
input="on"
fi
if [ "$input" = "on" ]; then
for (( i=0; i<${idLength}; i++ ));
do
xinput float ${id[$i]}
done
else
for (( i=0; i<${idLength}; i++ ));
do
xinput reattach ${id[$i]} ${master[$i]}
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment