I am trying to measure the time between a certain event displayed on the screen and until user responses with a input key in pygame. I hope to make the measurement as accurate as possible.
What is the expected/worst case latency in pygame? And, what are alternatives to read from keyboard faster?
Below is the code I am using right now to read from keyboard and measure the time.
def user_input(maxtime_msec):
time_start = time.time()
time_elapsed_msec = 0
key_press = False
while (time_elapsed_msec < maxtime_msec) and (not key_press):
for event in pygame.event.get():
if (event.type == pygame.KEYDOWN) and (event.key == pygame.K_RETURN):
key_press = True
else:
time.sleep(0.001)
time_end = time.time()
time_elapsed_msec = (time_end - time_start)*1000
return time_elapsed_msec