Advertisement
here2share

# b_wait4singlekeypress.py

Sep 7th, 2020
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. # b_wait4singlekeypress.py
  2.  
  3. import msvcrt, time
  4.  
  5. print "press 'escape' to exit..."
  6.  
  7. t = time.time()+1
  8. while 1:
  9.     char = msvcrt.getch()
  10.     if char == chr(27):
  11.         break
  12.     elif char == chr(13):
  13.         print 'return key was pressed'
  14.     elif char == ' ':
  15.         print 'spacebar was pressed'
  16.     else:
  17.         print char
  18.     if time.time() > t:
  19.         print 'this line prints after every 1 sec of the last pressed key'
  20.     t = time.time()+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement