Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Timing of canvas presentation in a loop


I have an issue I really have troubles figuring out with timing.
A simplified version of what I try to do is:

  • presenting a canvas;
  • then wait for a keyboard answer (timeout 800 ms).

So I just have in a loop and inline calling the canvas, then the keyboard, like:

in prepare:

python my_keyboard = keyboard(keylist=['SPACE']) my_keyboard.flush() python

in run
python var.time_present = show_stim(var.trial_shape).show() var.practice_key_pressed_Trial, var.pattern_abs_time_response_Trial = my_keyboard.get_key(timeout=800) python

show_stim is just a little function with the name of the canvas to display.
Anyway so when I do that I log the time of canvas presentation in var.time_present. Issue I have is that when I substract the difference between two var.time_present is not equal to 800 ms (well or to something close depending the refresh rate) and constant.
So I wonder if my canvas are staying for a same amount of time on the display.

I join a code example to this maybe it will be more understanble.




  • Hi Sylvain,

    some thoughts:
    1. my_keyboard.flush() does not make sense in prepare phase
    2. why do you insert a loop, and do not write it in python code? The rest is written in python code. Not sure whether this might fix your problem. But it's worth a try.

    pattern1 = canvas() #etc.
    #create a list of your stimuli
    new_list = (pattern1, pattern2)
    for i in range(10):
        new_list[i%2].present() #selects the first or the second
Sign In or Register to comment.