Created
September 5, 2010 16:03
-
-
Save dln/566113 to your computer and use it in GitHub Desktop.
Measure time between pressing 'space' key twice.
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
import sys | |
import termios | |
import time | |
import tty | |
def wait_space(): | |
if sys.stdin.read(1) == ' ': | |
return time.time() | |
return wait_space() | |
def measure(): | |
fd = sys.stdin.fileno() | |
attrs = termios.tcgetattr(fd) | |
print "Press space twice." | |
try: | |
tty.setraw(sys.stdin.fileno()) | |
start = wait_space() | |
delta = wait_space() - start | |
finally: | |
termios.tcsetattr(fd, termios.TCSADRAIN, attrs) | |
print "Time between presses: %0.04fs" % delta | |
if __name__ == '__main__': | |
measure() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment