Saving time of first mouse movement


I am trying to build an approach avoidance task, the response time should be the time from stimulus onset to the first mouse movement. Sadly, I cannot find any option in the builder which makes it possible to save the time of the first mouse movement.
I am not the best at coding, but maybe you can help me to write a code snippet which helps me to save the time of the first mouse movement. Furthermore, would it be possible to transfer this to an online experiment in Pavlovia?

A number of my demos save the position of the mouse in Begin Routine and then check for a movement each frame. Have a look at the ones designed for mobile devices.

I’m on my phone so not inclined to write out the code for you now.

Begin Routine

mouserec = mouse.getPos()
moved = False

Each Frame

if moved == False:
     mouseloc = mouse.getPos()
     if mouseloc[0] != mouserec[0] or mouseloc[1] != mouserec[1]:
          moved = True

Wow, thank you! It is working fine! Did not check it in an online setting yet, do you think it will be working as well?

It should definitely work online, since it’s based on the code I use for online. It just needs a mouse component called mouse (I usually put one in my first routine – it doesn’t have to be in the same routine as the code).

Maybe you can also help me with the following, I am now trying to implement feedback based on a variable in my conditionsfile (TargetPosition) and based on the position of the mouse on the y-axis.
I tried the following, but it is not working yet:

if ((TargetPosition == 'left') and ('mouse.y' < 0)) or ((TargetPosition == 'right') and ('mouse.y' > 0)):
    msg = 'wrong'

I get this error message:

if ((TargetPosition == 'left') and ('mouse.y' < 0)) or ((TargetPosition == 'right') and ('mouse.y' > 0)):
TypeError: '>' not supported between instances of 'str' and 'int'

Thank you in advance!

Why have you got mouse.y in quotes? That’s therefore a string.

In my code, mouse.y would be mouseloc[1]

I put it in quotes because without it, it was not working as well…

I tried mouse.y because in my output files it shows me the final position of the mouse, which is why I thought I could use it to provide feedback.

What do you mean by

In my code, mouse.y would be mouseloc[1] <

This coder saves the mouse position to a list.

mouseloc[0] is the x coordinate and mouseloc[1] is the y coordinate.

So if I add thisExp.addData('mouseloc') to my experiment, I can use it to provide feedback?

Sorry for all the questions, my coding skills are far from any skill level.

if ((TargetPosition == 'left') and (mouseloc[1] < 0)) or ((TargetPosition == 'right') and (mouseloc[1] > 0)):
    msg = 'wrongt'
elif((TargetPosition == 'right') and (mouseloc[1] < 0)) or ((TargetPosition == 'left') and (mouseloc[1] > 0)):
    msg = 'correct'
    msg = 'to slow'

Now it is working as it is supposed to be!

1 Like

I did move it to Pavlovia by now, now I am facing another problem.

Because I want every trial to start with the cursor in a centralized position, I inserted the following code in BeginRoutine tab

mouse.setPos((0, 0))

Sadly, it seems like this does not work on pavlovia do you know an alternative which should work on pavlovia?

What you can do is ask participants to click on something in the centre of the screen to get them to move their mouse back to the centre.

Ok, so I guess I will tell the participants to move their cursor towards the fixation cross.

You can force this by making a fixation routine which ends on a valid click on the cross.

Oh, cool idea, that way I can also make sure to keep participants’ attention! Thank you again and again!