| Reference | Downloads | Github

event.waitKeys timeStamped not working


I ran into problems using event.waitKeys method. When I set the timeStamped attribute to True, it does not return anything and just leaves it blank.

Here’s my code:

from psychopy import visual, event, core
import sys

win = visual.Window(
    size=[400, 400],
    color=[-1, -1, -1],

fixation = visual.ShapeStim(
    vertices=((0, -20), (0, 20), (0, 0), (-20, 0), (20, 0)),


clock = core.Clock()
response = event.waitKeys(timeStamped=True)
time = clock.getTime()
print time, response


And here’s what I would get:

0.868468999863 [('i',)]

Still, if I set the attribute to clock, I would normally get something like this:

0.868468999863 [('i', -1.8378880023956299)]

which is also abnormal and beyond me. Does anyone here know what is wrong?


response = event.waitKeys(timeStamped = clock, clearEvents = True)

Thanks for the reply. But that does not work. My PsychoPy says no atttribute ‘clearEvents’ for waitKeys.

I tried:

response = event.waitKeys(timeStamped=clock)

but it does not work either.

Your code (in your first post) works fine for me (1.85.3, Linux):

with timeStamped=True: 0.605473041534 [('i', 1.588170051574707)]
with timeStamped=clock: 0.762838840485 [('i', 0.7627718448638916)]

What is your psychopy version and OS?

Like @djmannion, your code works fine for me too (1.85.4, Mac).

You do seem to have hit on a weird bug with this though:

TypeError: waitKeys() got an unexpected keyword argument 'clearEvents' 

I can replicate that as well. That isn’t the cause of your issues, but is really strange.

That’s new in 1.85.4 I think - I don’t have that argument in 1.85.3. Though that doesn’t explain why you are getting the error on 1.85.4.

Ahh, I was looking in the source code for my developer installation but was actually running the code on the 1.85.4 Standalone. The clearEvents parameter must still be upstream only and not yet released. Unfortunately; the online API documents are ahead of the released version.

I am running psychopy 1.85.4 on macOS. Still not sure how this bug can be fixed. Workaround is possible, though, given that what I need is just the response time.

Anyway, thanks for replying!

Having issues like this on Windows 10 Pro Build 18362 with an NVIDIA graphics card on Psychopy 3.2.0:

key_list = ["left", "right"]
keys = event.waitKeys(keyList=key_list, timeStamped=rt_clock)

This ends up printing negative timestamps like: keys = [['right', -7.34115810000003]]
Using timeStamped=True does not give any timestamp at all, only showing the key pressed. Adding clearEvents=True does not make any difference.

Would need to know more details to help here, but anyway instead would advise that you upgrade to the new Keyboard class, which supersedes and is far superior to the old event module in terms of timing.