Hi all,
In my experiment, I schedule the presentation of a stimulus by defining a list of timepoints and waiting for a timepoint by using a while-loop. Meanwhile, I want to capture any keyboard event with its precise timing. Here’s a rough idea of the code logic:
timer = core.Clock()
kb = keyboard.Keyboard(clock=timer)
timepoints = [1.0, 1.5, 2.5]
for timepoint in timepoints:
stimulus.draw()
win.flip()
while timer.getTime() < timepoint:
continue
When looking at the log file, it turns out that all keyboard events were recorded but only with timestamps close to the entries in the timepoints
list. Now I included either a win.flip()
or core.wait(0.01, hogCPUperiod=0.01)
command in the while-loop, which solves the issue and captures the precise keyboard events. However, I am wondering why these extra commands are necessary and if there is a best practice regarding this problem.