Skip to content

Instantly share code, notes, and snippets.

@plu5
Created January 14, 2025 01:26
Show Gist options
  • Select an option

  • Save plu5/b0eb53f9af086f2297358c4406a38c24 to your computer and use it in GitHub Desktop.

Select an option

Save plu5/b0eb53f9af086f2297358c4406a38c24 to your computer and use it in GitHub Desktop.
Linux X toggle keyboard script
#!/bin/bash
# use `xinput list` to check your keyboard name. this one is for laptop internal keyboard
deviceName="AT Translated Set 2"
builtInId=$(xinput list | grep "$deviceName" | sed 's/^.*id=//' | sed 's/\t.*//')
case $1 in
disable)
xinput disable $builtInId
echo "Keyboard '${deviceName}' disabled"
;;
enable)
xinput enable $builtInId
echo "Keyboard '${deviceName}' enabled"
;;
*)
echo "Toggle keyboard '${deviceName}' (id ${builtInId})"
echo "Invalid options"
echo "Syntax: $0 enable/disable"
exit
;;
esac
# if you have an xmodmap config you need to reapply it
xmodmap ~/.Xmodmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment