Latency in reading from keyboard input in Pygame
<p>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. </p>

<p>What is the expected/worst case latency in pygame? And, what are alternatives to read from keyboard faster?</p>

<p>Below is the code I am using right now to read from keyboard and measure the time.</p>

<pre><code>def user_input(maxtime_msec): 
    time_start = time.time() 
    time_elapsed_msec = 0 
    key_press = False
    while (time_elapsed_msec &lt; 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
</code></pre>