Disable touch screen

Question: Is there a way to disable the touch screen? I’d like participants to use a mouse or trackpad for an online study.

Touchscreen mouse behaviour could be spotted with large jumps in the coordinates.

1 Like

coord_data.csv (1016.5 KB)
I think that would work if there were intermittent clicks, but I’m not sure about when the task involves drawing or tracing. In the attached data, some of the trials are touchscreen and some are mouse. If the touchscreen can’t be disabled, I would hope to figure out some way to discriminate between the trials. The touch also registers as a left mouse click, but perhaps there’s a way to detect a touchscreen response specifically?

Partial answer: you could listen for touchstart events, and warn the participant/stop the task if any are detected? e.g.

let canvas = ... // access the canvas somehow. Maybe `win._renderer.view`?
let cb = (evt) => { console.error("no touchscreens"); }
canvas.addEventListener("touchstart", cb, false)

Which seems like it could work in most situations (mobile devices & laptop with touchscreen properly detected), though it isn’t currently supported in Safari or Internet Explorer. More Touch API details here: Touch events - Web APIs | MDN

Unfortunately, I don’t have any good tips for how you could integrate this (probably a custom code component if this is in Builder?).

1 Like

Thanks aforren1, that’s a good idea to think about. I’m not quite sure how it might work either, and whether the touch listener would be able to discriminate between a trackpad and an actual touchscreen. I might try to look into this option, although it would be most convenient to figure out a way to do this regardless of browser type.

Warning: a work in progress

I’ve been toying with enabling multi-touch on touch screen devices for another project and have something that I hope might help you
run link: https://run.pavlovia.org/lpxrh6/multitouch_demo
files link: Pavlovia

Essentially you monitor for ongoing touch events in the way that @aforren1 describes. This is implemented by replacing the addMouseEventListeners in the core module I therefore import a custom psychojs library here. You can then check inside your experiment how many ongoing touches there are by checking the length of psychoJS.ongoingTouches. For your purposes, you would want to check this was 0, which would mean there were no current touch events.

This is still a work in progress so needs tweaks and improvements, but I hope that you find it helpful. Let me know if you have questions,

EDIT: I notice that the version I shared here might be an old version where the circle is always assigned the first touch event, for your purposes you only need to know nTouches, so this should be ok, but I’ll be updating the demo with the more recent update asap

1 Like

Thanks for this Becca, psychoJS.ongoingTouches in the custom library works like a charm.
To sum up, we can’t disable the touchscreen (which could still be a potentially convenient feature), but it seems likely that people are moving in the direction of more, rather than less touchscreen. A touch press is logged as a left mouse click, but psychoJS.ongoingTouches is unique to a touch screen (and not trackpad). I’m marking this as the solution.

1 Like

Summarized perfectly - can’t currently disable just monitor - pleased this helps!


Hi Becca,
I noticed a new option for mouse data to save only on valid clicks. Is that setting related to touchscreen touches? We’re looking into the touchscreen issue again this year and wondering if there’s a better solution than using the custom packages you kindly provided previously.
PS. @Becca

Hi Paul,

This option relates to touch screen and mouse click responses. Unfortunately there still isn’t an inbuilt method to prevent touch screen responses, though I did work on a touchscreen test that is a little more elegant than I previously provided. You can quite easily check if a person is using a touchscreen by seeing if a cursor location passes through an invisible boundary in the center of the screen (if using a touchscreen the cursor coordinates “jump” and don’t pass through a boundary).

Here’s a gif and link to the repo! https://twitter.com/HirstRj/status/1483058260815093760?s=20&t=vF34agTo6Bw5dCZowZFhDQ

Hope this helps,

1 Like

Hi Becca,
Thanks for the followup! I actually find the libraries you provided previously to be tremendously useful (especially considering that participants can switch back and forth between touchscreen and trackpad).
Looking forward to seeing the ongoing touches feature implemented in PsychoJS someday maybe :smile:

Maybe this post will give me the nudge to get it in PsychoJS :joy: :muscle: (it’s lovely to know someone is using some code I made once!)