psychopy.org | Reference | Downloads | Github

Using the mouse to move through a scale


#1

Hi, I am A MRes student and have created an adaptation paradigm of varying BMI ranges using PsychoPy. However, theres is one part of the experiment I am struggling to complete. I am wanting to have a scale where the participant can move their mouse left or right and move through the scale. This scale needs to include images of different body sizes going from very thin to very large. I have all of these images saved to my laptop. Currently, I am using the left and right arrows to move through this scale but wish to change it to be operated by the mouse using left and right movements. I also wish to not have this scale present/visible on the screen (so all the participant can see is the body images when they move their mouse not a scale).

The current code which I am using is:
Begin Routine:

import glob
import os
from random import choice

wd = os.getcwd()
directory = str(wd + '/adaptation/images/')
imgLst = glob.glob(str(directory + '*.png'))

choices =[0, (len(imgLst)-1)]

startIndex = choice(choices)
img = imgLst[startIndex] #Make this variable the image of your stimulus 
currentIndex = startIndex # to avoid running the function on every run

Each Frame:

key = event.getKeys(keyList=['left', 'right', 'escape', 'return'])

if len(key) == 0:
    pass
elif key[0] == 'return':
    endPoint = imgLst[currentIndex]
    thisExp.addData('EndPoint', endPoint)
    continueRoutine = False
elif key[0] == 'right':
    currentIndex += 1 # advance image index
    if currentIndex >= len(imgLst)-1:
        currentIndex = len(imgLst)-1
    img = imgLst[currentIndex]
elif key[0]== 'left':
    currentIndex -= 1
    if currentIndex == -1: # Stop out of bounds
        currentIndex = 0
    img = imgLst[currentIndex]

event.clearEvents()