Skip to content

Touch behavior is strange when only mouse interaction is described #7260

@inaridarkfox4231

Description

@inaridarkfox4231

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.9.1

Web browser and version

Chrome

Operating system

Windows

Steps to reproduce this

Steps:

  1. Describe the interaction using only mousePressed and mouseReleased.
  2. Inside the draw loop, use mouseIsPressed to perform console output.
  3. In the case of touch, mousePressed and mouseReleased are executed in this order at the timing of release.

Snippet:

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  if(mouseIsPressed){
    console.log("is");
  }
}

function mousePressed(){
  console.log("mousePressed");
}

function mouseReleased(){
  console.log("mouseReleased");
}
2024-09-10.23-30-17.mp4

Note that I use a stylus pen for touch because to check on a desktop, but the results are the same on a mobile phone.

In the above code, in the case of touch, only the processing at mouseIsPressed is executed, and at the timing of release, the contents of mousePressed and mouseReleased are executed in this order.

However, the following code achieves the intended behavior even on touch operations. In other words, first mousePressed is executed, then the process for mouseIsPressed is executed in the draw loop, and finally mouseReleased is executed.

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  if(mouseIsPressed){
    console.log("is");
  }
}

function touchStarted(){
  console.log("mousePressed");
}

function touchEnded(){
  console.log("mouseReleased");
}

Regarding the mouse, either code results in the intended behavior.

In other words, if you only describe the interaction when using the mouse, mousePressed() will not be executed when touch is started.

Furthermore, in the case of the first code above, if the start and end positions of the touch are different, neither mousePressed nor mouseReleased seems to be executed.

2024-09-10.23-56-55.mp4

It's hard to see in the video, but if you touch it, move it, and then release it, none of the processes will be executed. Any second code will be executed.

OpenProcessing: Interaction bug

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions