# Disable touch screen

**URL:** <https://discourse.psychopy.org/t/disable-touch-screen/23614>\
**Category:** Online experiments\
**Tags:** mouse\
**Created:** [June 17, 2021, 8:44pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614 "2021-06-17T20:44:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![plonskipe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/plonskipe/32/16030_2.png) [@plonskipe](https://discourse.psychopy.org/u/plonskipe)\
**Post date:** [June 17, 2021, 8:44pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/1 "2021-06-17T20:44:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [June 17, 2021, 10:04pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/2 "2021-06-17T22:04:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![plonskipe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/plonskipe/32/16030_2.png) [@plonskipe](https://discourse.psychopy.org/u/plonskipe)\
**Post date:** [June 18, 2021, 12:21pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/3 "2021-06-18T12:21:49Z")

</div>

[coord\_data.csv](https://discourse.psychopy.org/uploads/short-url/pAMNPFkCwgaxiMFphFmaXUP8wi0.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?

---

<div class="post-metadata">

**Author:** ![aforren1](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aforren1/32/44286_2.png) [@aforren1](https://discourse.psychopy.org/u/aforren1)\
**Post date:** [June 18, 2021, 1:38pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/4 "2021-06-18T13:38:09Z")

</div>

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

```auto
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](https://developer.mozilla.org/en-US/docs/Web/API/Touch_events)

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

---

<div class="post-metadata">

**Author:** ![plonskipe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/plonskipe/32/16030_2.png) [@plonskipe](https://discourse.psychopy.org/u/plonskipe)\
**Post date:** [June 18, 2021, 5:42pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/5 "2021-06-18T17:42:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [June 18, 2021, 8:32pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/6 "2021-06-18T20:32:30Z")

</div>

**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](https://run.pavlovia.org/lpxrh6/multitouch_demo)  
files link: [Pavlovia](https://pavlovia.org/lpxrh6/multitouch_demo)

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,  
Becca

**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**

---

<div class="post-metadata">

**Author:** ![plonskipe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/plonskipe/32/16030_2.png) [@plonskipe](https://discourse.psychopy.org/u/plonskipe)\
**Post date:** [June 21, 2021, 4:09pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/7 "2021-06-21T16:09:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [June 21, 2021, 4:27pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/8 "2021-06-21T16:27:23Z")

</div>

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

Becca

---

<div class="post-metadata">

**Author:** ![plonskipe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/plonskipe/32/16030_2.png) [@plonskipe](https://discourse.psychopy.org/u/plonskipe)\
**Post date:** [May 6, 2022, 7:55pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/9 "2022-05-06T19:55:04Z")

</div>

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.  
Thanks,  
Paul  
PS. @Becca

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [May 7, 2022, 9:13am UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/10 "2022-05-07T09:13:17Z")

</div>

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](https://twitter.com/HirstRj/status/1483058260815093760?s=20&t=vF34agTo6Bw5dCZowZFhDQ)

Hope this helps,  
Becca

---

<div class="post-metadata">

**Author:** ![plonskipe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/plonskipe/32/16030_2.png) [@plonskipe](https://discourse.psychopy.org/u/plonskipe)\
**Post date:** [May 7, 2022, 1:07pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/11 "2022-05-07T13:07:18Z")

</div>

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 😄

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [May 7, 2022, 3:47pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/12 "2022-05-07T15:47:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hurry01](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/hurry01/32/42232_2.png) [@hurry01](https://discourse.psychopy.org/u/hurry01)\
**Post date:** [July 14, 2024, 5:44pm UTC](https://discourse.psychopy.org/t/disable-touch-screen/23614/13 "2024-07-14T17:44:15Z")

</div>

Hi Becca,

My name is Heather and I work with Paul (Dr. Plonski as of 10 July 2024!). The solution you generated to count the number of touchscreen touches has been working well for us for a few years now and we really appreciate it! I’d now like to use PsychoPy 2024.1.5. Is it possible to import psychoJS.ongoingTouches from ‘./custom-lib/core-2021.1.3.js’ but stil run 2024.1.5? I have tried a few things unsuccessfully. Thank you in advance for any pointers here.

Heather
