Created
April 22, 2015 13:15
-
-
Save cvubrugier/2868ab3bc66e9ba5cc14 to your computer and use it in GitHub Desktop.
Ugly script that intercepts keypress on Linux with Python
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/python | |
from __future__ import print_function | |
import sys | |
import termios | |
import tty | |
def main(): | |
fd = sys.stdin.fileno() | |
old_settings = termios.tcgetattr(fd) | |
try: | |
tty.setraw(sys.stdin.fileno()) | |
r = sys.stdin.read(5) | |
finally: | |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | |
print('r = %r' % r) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment