Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. from time import sleep
  4. from sys import stdin
  5. from select import select
  6. from tty import setcbreak
  7. from termios import TCSADRAIN, tcgetattr as getat, tcsetattr as setat
  8.  
  9.  
  10. def readCh():
  11. if select([stdin], [], [], 0) == ([stdin], [], []):
  12. return stdin.read(1)
  13. return False
  14.  
  15. def readKey(time=.1):
  16. key = stdin.read(1)
  17. sleep(time)
  18. while True:
  19. ch = readCh()
  20. if not ch:
  21. break
  22. key += ch
  23. sleep(time)
  24. return key
  25.  
  26.  
  27. if __name__ == "__main__":
  28. try:
  29. oldSettings = getat(stdin)
  30. setcbreak(stdin.fileno())
  31.  
  32. key = readKey()
  33. print "key:", repr(key)
  34. finally:
  35. setat(stdin, TCSADRAIN, oldSettings)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement