Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created February 10, 2016 19:53
Show Gist options
  • Save meeuw/a99da8ffc1b241ff2465 to your computer and use it in GitHub Desktop.
Save meeuw/a99da8ffc1b241ff2465 to your computer and use it in GitHub Desktop.
#!/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