Skip to content

Instantly share code, notes, and snippets.

@draplater
Created March 1, 2015 01:59
Show Gist options
  • Save draplater/2bc4f8ba41cf49fb2d8c to your computer and use it in GitHub Desktop.
Save draplater/2bc4f8ba41cf49fb2d8c to your computer and use it in GitHub Desktop.
switch keyboard state
#!/bin/sh
#if ! xinput | grep -q "Poker II"; then
if ! lsusb -v 2> /dev/null | grep -q Keyboard; then
echo "No external keyboard"
exit 1
fi
keyboard_id=$(xinput | grep "AT Translated Set 2 keyboard" | grep -Po "(?<=id=)\d+")
if xinput | grep "AT Translated Set 2 keyboard" | grep -q "slave keyboard"; then
xinput float $keyboard_id
echo "Keyboard floated."
else
master_id=$(xinput | grep "master keyboard" | grep -Po "(?<=id=)\d+")
xinput reattach $keyboard_id $master_id
echo "Keyboard attached."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment