Howdy, Stranger!

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

Supported by

Getting reaction time during a canvas.show()

Hello!

So I am confused about how to record the time it takes for a mouse click when a canvas appear on the screen.
The thing I want to do is as follow:

  • I present a canvas;
  • I wait for a mouseclick to make it disappear.

So here is the code I used for now:

<br />t = my_canvas_Practice_Sym.show()
my_mouse = Mouse(visible=False) 
button, position, timestamp = my_mouse.get_click()

while True:
    if button is not None:
        break

var.reaction_time_canvas = timestamp - t


There are two things I am wonder here:

  • could you confirm that timestamp corresponds to the time of the mouseclick and not the time when the mouse is initiated?
  • I wonder if my approach is the best here for timing accuracy. First I draw the canvas and second I initiate the mouse. Could you confirm the time it takes to the mouse to initiate is so small it doesnt matter?

Thank you!

Comments

  • Hi,

    could you confirm that timestamp corresponds to the time of the mouseclick and not the time when the mouse is initiated?

    Confirmed.

    I wonder if my approach is the best here for timing accuracy. First I draw the canvas and second I initiate the mouse. Could you confirm the time it takes to the mouse to initiate is so small it doesnt matter?

    Probably true, but given the ease with which to fix it, there is no reason why not optimizing it.

    Also, yourwhile loop doesn't do anything currently. The button is pressed before, so that the while loop is effectively skipped. If you set the timeout of the mouse response to something else than infinite, you will probably even end up in an infinite loop. So, to fix it, here two suggstions:

    1) Drop the while loop and use the timeout keyword:

    # advantage: it is more straightforward and you write less code
    my_mouse = Mouse(visible=False,timeout = 2000) # 2 seconds timeout 
    # show
    t = my_canvas_Practice_Sym.show()
    button, position, timestamp = my_mouse.get_click()
    var.reaction_time_canvas = timestamp - t
    

    2) Combine timeout and while loop

    # advantage: This code is more flexible and you could add other computations to the loop
    my_mouse = Mouse(visible=False,timeout = 2) # 2 MILLISECONDS timeout 
    # show
    t = my_canvas_Practice_Sym.show()
    while True:
        button, position, timestamp = my_mouse.get_click()
        if button != None:
            var.reaction_time_canvas = timestamp - t
            break
    

    Hope this helps.

    Eduard

  • Hey Eduard!

    Thanks a lot yes it helps! I just do not understand why in the first example the canvas stop after a mouse click. I mean there is nothing indicating that my_canvas_Practice_Sym.show() should disappear after a mouse click no?

    Thank you!

    Sylvain

  • Hi,

    I think this is because the experiment is simply over, no? If you have a sleep statement after the loop, it would stay on screen? But I must admit I haven't tried it myself.

    Eduard

  • Hey Eduard,

    No I just meant with your example:

    # advantage: it is more straightforward and you write less code
    my_mouse = Mouse(visible=False,timeout = 2000) # 2 seconds timeout 
    # show
    t = my_canvas_Practice_Sym.show()
    button, position, timestamp = my_mouse.get_click()
    var.reaction_time_canvas = timestamp - t
    

    I do not get how

    my_canvas_Practice_Sym.show()
    

    Stop after a mouse click. Implicitely does it mean that showing the canvas just update the screen (like if we would set up a duration of 0ms to a sketchpad) and the script progress to the mouse object?
    I was assuming that when my_canvas_Practice_Sym.show() was called somewhat it was staying active (updating the screen indefinitely) but it is just a call to a single update of the screen right?

    Thank you!

    Best,

    Sylvain

  • HI,

    Yes, it is a single call. Basically, once updating the screen and showing the canvas and then immediately proceeding to the mouse response and waiting for a click until the end of the timeout (2000ms). Once it was clicked (or time is up) it will proceed with the code below, or in case there is no code anymore, with the next item in the sequence. Does that make sense?

    Eduard

    Thanked by 1Sylvain
  • Hey Eduard,

    Yes I get it, it makes sense. It is like a single update of the screen. Much more simple than what I imagined!

    Thanks!

    Best,

    Sylvain

Sign In or Register to comment.