Created
May 27, 2020 12:22
-
-
Save BlurryLight/4b4326be785eeeb53baa73030a2bd8e8 to your computer and use it in GitHub Desktop.
linux-disable/enable-laptop-internal-keyboard
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 python | |
#encoding: utf-8 | |
import subprocess | |
import sys | |
keyboard_id = subprocess.check_output("xinput list | grep 'AT Translated Set' | cut -f2 | cut -d'=' -f2",shell=True).decode('utf-8').strip('\n') | |
master_keyboard_id = subprocess.check_output("xinput list | grep 'master keyboard' | cut -f2 | cut -d'=' -f2",shell=True).decode('utf-8').strip('\n') | |
if len(sys.argv) > 1: | |
if(sys.argv[1] == 'detach'): | |
subprocess.run("xinput float " + str(keyboard_id),shell=True) | |
print("disable keyboard") | |
elif (sys.argv[1] == 'reattach'): | |
command = "xinput reattach " + str(keyboard_id) + ' ' + str(master_keyboard_id) | |
print(command) | |
subprocess.run(command,shell=True) | |
print("enable keyboard") | |
else: | |
print(sys.argv[0] + " detach/reattach ") | |
else: | |
subprocess.run("xinput float " + str(keyboard_id),shell=True) | |
print("disable keyboard") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment