Last active
August 31, 2022 19:00
-
-
Save auroracramer/64fa76aa82da717a520a28ec25304a66 to your computer and use it in GitHub Desktop.
Utility for toggling keyboard. Created so I can write on my laptop keyboard when it's open. I'm using it as a GNOME launcher application for Ubuntu 18.04 that can be access with the mouse. UPDATE: Doesn't work on Ubuntu 22.04 since it uses the Wayland window manager :(
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
KEYBOARD_INFO=$(xinput list | sed -e 's/ */ /g' | grep "AT Translated Set 2 keyboard") | |
EXTRAKEY_INFO=$(xinput list | sed -e 's/ */ /g' | grep "ThinkPad Extra Buttons") | |
KEYBOARD_ID=$(echo $KEYBOARD_INFO | grep -o -P 'id=\K\d*') | |
EXTRAKEY_ID=$(echo $EXTRAKEY_INFO | grep -o -P 'id=\K\d*') | |
MASTER_ID=$(xinput list | sed -e 's/ */ /g' | grep -o -P 'slave keyboard \(\K\d*' | head -n 1) | |
IS_ATTACHED=$([ -z "$(echo $KEYBOARD_INFO | grep -o -P 'floating slave')" ]) | |
if [ -z "$(echo $KEYBOARD_INFO | grep -o -P 'floating slave')" ]; then | |
xinput float $KEYBOARD_ID | |
xinput float $EXTRAKEY_ID | |
echo "Disabled keyboard" | |
else | |
xinput reattach $KEYBOARD_ID $MASTER_ID | |
xinput reattach $EXTRAKEY_ID $MASTER_ID | |
echo "Re-enabled keyboard" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment