Skip to content

Instantly share code, notes, and snippets.

@Davidblkx
Created May 18, 2020 22:43
Show Gist options
  • Save Davidblkx/cf8cb914a2648b058c9db5b34b82b47b to your computer and use it in GitHub Desktop.
Save Davidblkx/cf8cb914a2648b058c9db5b34b82b47b to your computer and use it in GitHub Desktop.
Enable/Disable laptop keyboard using XINPUT
#/bin/bash
#######################################
# Enables or disables laptop keyboard #
#######################################
# Keyboard name to work with
KB_NAME="AT Translated Set 2 keyboard"
# Grab keyboard ID
KB_ID=$(xinput list | grep "$KB_NAME" | awk '{ print $7 }' | sed -r 's/id=//g')
# Grab slave keyboard ID
KB_SLAVE_ID=$(xinput list | grep "slave keyboard" | awk -F"[()]" 'NR==1{ print $2 }')
# Check if is in float mode, 1 = float
KB_IS_DISABLED=$(xinput list | grep 23 | awk '/floating/{ print "1" }')
# If is in float, reattach
if [ "$KB_IS_DISABLED" = "1" ]; then
xinput reattach "$KB_ID" "$KB_SLAVE_ID"
echo "Enabled"
exit
fi
# Disable
xinput float "$KB_ID"
echo "Disabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment