psychopy.org | Reference | Downloads | Github

Touchscreen response mode in laptop

OS: Win10
PsychoPy version: 3.2.4
What are you trying to achieve?:
I have designed a cued switching task for children, where they had to sort some toys based on their color or shape. The outline of the experiment is as follows:
There will be four stimuli: Red Bear, Blue Bear, Red Car, and Blue Car.
If the cue is for color, participants have to select either blue or red color, whereas if the cue is for shape, they have to select either bear or car. So, there are four response options: A=Blue, S=Red, K=Bear, L=Car.
I have to take responses here using a touchscreen. And that’s where the problem is occurring. There are four response pictures from which the participant has to touch one as a response. Similarly, in all trials he has to do the same. I tried using the .contains() method.
I kept the following code:
for stimulus in stimuli:
if stimulus.contains(mouse) and stimulus.name == corrAns:
thisExp.addData(‘clicked_stimulus’, stimulus.name)
continueRoutine = False
break

Here, the stimulus does not appear when the trial runs. Also, in further trials, the target somehow does not appear.
I also want to know the reaction time of the click. What other modifications in the code can I do to have the name and reaction time of the clicked stimulus.

Thank you in advance

The main problem I have with touchscreens is that the location of the mouse stays in the same place when you stop touching the screen. You therefore might be whizzing through the rest of the trials at one frame each. The way I deal with this is to record the location of the mouse just before I’m willing to accept a response and only accept a response if the coordinates are different from the previously recorded location in addition to the contains I want.

I tend to record the reaction time using t, which is the time since the beginning of the routine.

I am having the same issue using a touch screen. Your description of the solution seems exactly like what I need. Having only a little experience with coding so far, I’m not able to implement your solution in the code builder. Would you be willing to share some of your code with me so I can reference it? Thanks!

Begin Routine

mouserec = mouse.getPos()

Each Frame

mouseloc = mouse.getPos()
if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
    pass
elif image_1.contains(mouse):
    mouserec = mouseloc
    answer=1
    feed1='one_yellow.png'
    feed2='two_white.png'
    continueRoutine = False
elif image_2.contains(mouse):
    mouserec = mouseloc
    answer=2
    feed1='one_white.png'
    feed2='two_yellow.png'
    continueRoutine = False

Thanks Carter. I can see the mouseloc and mouserec as the way to prevent the trials from running through because the mouse is left in its position on the touch screen.

It isn’t as clear to me what the two elif statements accomplish after the ‘pass’. I’m assuming the feed1 and feed2 are specific to the your experiment. But I want to check if that part of the code is necessary to prevent the touch screen issue. Your help is appreciated.

elif objectName.contains(mouse): is needed to do something with a touchscreen response. The object can be an image or a polygon but not text (yet).

Put a mouse component called mouse in your first routine. You don’t need a new mouse component in later routines if you use code components