[open] Timing of Keyboard response every screen flip?
Hi!
I'm using inline scripts to present a moving stimuli on screen and collect a keyboard response. This is done with a for loop to alternatively show the canvas and sample the keyboard response. I'm using PsychoPy as the back-end.
I'm concerned about the timing of the response collection. If i understand the way this works, in the best case in which i'm showing the canvas in perfect synchronization with the flips, i'm actually sampling the keyboard just ones every flip (+/- 17 ms).
I ran a simple test and printed the time stamps of the get.key function, and indeed this is the case.
[0.0, 10.490376022062264, 27.110606264614034, 43.78133021964459, 60.450001579738455, 77.11949398071738, 93.86985841774731, 110.51102507553878, 127.17271763176541, 143.8561676441168, 160.43821971470607, 177.10114382498432, 193.76324690165347, 210.4783067952667, 227.16380939164083, 243.83781748838373, 260.496225902898, 277.1644867498253, 293.7916957962443, 310.49361911573214, 327.1368383648223, 343.78539434692357, 360.4959385411348, 377.09974806421087, 393.76020907002385, 410.3964495116088, 427.0642998380936, 443.71696100279223, 460.4250420889002, 477.0625140845368, 493.7270802693092, 510.41997218999313, 527.1539159111853, 543.7076422422251, 560.4169548860227, 577.0470375573495, 593.712424779369, 610.4159901660751, 627.0247259089956, 643.702839184698]
The effect i'm looking for in the experiment is pretty small. Any chance I can get more accurate keyboard timing? (other than the parallel plug-in, which i understand is not that stable and also I want the keyboard response to terminate the motion which is not possible in this method).
Thank you very much in advance!
Yoni
Comments
Hi Yoni,
Yes, your understanding is correct. If you call
keyboard.get_key()
with a timeout of 0 ms, and then do acanvas.show()
, the experiment will spend most of the time waiting for the start of a new refresh cycle.A simple solution would be to use a timeout that is slightly less than one frame duration. Say 14 ms if you have a 16.7 ms frame duration. That way, once the keyboard times out, it will be almost time for the next frame, and the experiment won't spend much time waiting for the start of a new refresh cycle. Does that make sense?
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
As always, your answers make perfect sense.
Thanks a lot!
Yoni