Mouse click conditional feedback

You currently need code for scoring mouse clicks in PsychoPy.

You might find my Emotional Stroop for mobile online demo useful.

Here I’ve used the following code in Each Frame

if t < .5:
    mouserec = mouse.getPos()
else:
    mouseloc = mouse.getPos()
    if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
        pass
    elif button1.contains(mouse):
        response=0
        butcol1='yellow'
    elif button2.contains(mouse):
        response=1
        butcol2='yellow'
    elif button3.contains(mouse):
        response=2
        butcol3='yellow'
    elif button4.contains(mouse):
        response=3
        butcol4='yellow'
    if response < 99:
        if response==thisColour:
            Score = 1
        continueRoutine=False

For touchscreens I use the contains method combined with a change in coordinates rather than waiting for a click.

This code translates the mouse response into a variable (response) and changes the colour of the pressed button for feedback.

The feedback code is in End Routine and includes code for the possibility of a parallel keyboard response.

block_results[thisBlock[2]][0]+=1
if Response.corr == 1 or Score == 1:
    block_results[thisBlock[2]][1]+=1
    rtList.append(round(t*1000)-500)
    feedbackImage='tick_white.png'
else:
    feedbackImage='cross_white.png'
    
if thisBlock[2] > 0:
    showFeedback = 0