pythonpsychopyscrollwheel

psychopy record time of last mouse scroll wheel movement


I need to record the last time the scroll wheel was moved for each trial. I have code that does this for key presses (the lastTrialTime variable):

 lastTime = 0 # setting up to get RT at last key press
    while timer.getTime() >0: # while time isn't up (turns neg when time's up)
        for key in event.getKeys():
            if key in ['escape']:
                core.quit() # quit if they press escape
            if key in ['b']:
            # add keypress to list for each keypress. then move cursor proportionally to length of this list
                b_list.append(key)
                prevPos+=len(b_list)
                lastTime = clock.getTime()
            if key in ['t']:
                t_list.append(key)
                prevPos-=len(t_list)
                lastTime = clock.getTime()
        lastTrialTime = lastTime

but I'm not sure how to do it for mouse responses. I use the following line of code to get how much the scroll wheel is moving on each refresh.

wheel_dX, wheel_dY = myMouse.getWheelRel()*4

However, I can't figure out how to use that (or something else?) to make a variable that contains a clock.getTime() call for the last scroll wheel movement.


Solution

  • You can test whether the values are 0 or not:

    wheel_dX, wheel_dY = myMouse.getWheelRel()*4
    if any([wheel_dX, wheel_dY]):
        lastTime = clock.getTime()