Created
February 10, 2016 19:53
-
-
Save meeuw/a99da8ffc1b241ff2465 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/python3 | |
import tty | |
import termios | |
import sys | |
import subprocess | |
def getchar(): | |
#Returns a single character from standard input | |
fd = sys.stdin.fileno() | |
old_settings = termios.tcgetattr(fd) | |
try: | |
tty.setraw(sys.stdin.fileno()) | |
ch = sys.stdin.read(1) | |
finally: | |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | |
return ch | |
print("UNLOCK <=== SWIPE ===> LOCK") | |
while 1: | |
c = getchar() | |
if c == "\x01": | |
ctrla = True | |
elif ctrla and c == "p": | |
subprocess.check_call("loginctl unlock-session 1", shell=True) | |
ctrla = False | |
elif ctrla and c == "n": | |
subprocess.check_call("loginctl lock-session 1", shell=True) | |
ctrla = False | |
elif ctrla and c == "q": | |
sys.exit() | |
else: | |
ctrla = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment