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 == corrAns:
continueRoutine = False

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]:
elif image_1.contains(mouse):
    mouserec = mouseloc
    continueRoutine = False
elif image_2.contains(mouse):
    mouserec = mouseloc
    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

Thank you for your help. My experiment is now working with touchscreen properly.
My current issue is that I want to add a column of ‘correct’ where I can have a list of 1s and 0s depending on whether the response image clicked/touched was correct. Also, I want to provide a feedback to let the participant know whether they have responded correctly or not.

The following is my code component:


Here is my excel file:


In the excel file I have added the name of the image component which is supposed to be the correct answer and which will be displayed in the column ‘clicked_Resp’ in the data file. Is this correct or should I put the image name, as I have kept in the column “ImagePIC_P”?

It would be great if you could help me with it.
Thank you