Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mouseButton on touch device gives 0 for first click (and for any long presses before the first click) #7397

Open
17 tasks
eyaler opened this issue Nov 28, 2024 · 4 comments
Labels

Comments

@eyaler
Copy link

eyaler commented Nov 28, 2024

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.11.1

Web browser and version

firefox 133 android, chrome 131 android

Operating system

android

Steps to reproduce this

mouseButton on touch device gives 0 for first click (and for any long presses before the first click). only presses after that first click give 'left'.

Steps:

  1. run on a touch device
  2. note that the first click shows mouseButton value to be 0
  3. note that only on second click it changes to 'left'
  4. rerun and now do long presses instead of clicks. note that the value is 0 until you do the second click

Snippet:

function setup() {
  createCanvas(100, 100)
}

function touchStarted() {
  background(200)
  text(mouseButton, 50, 50)
}

or run this

@eyaler eyaler added the Bug label Nov 28, 2024
@wayneharish10
Copy link

As we can see from code, touchStarted doesn't set mouseButton, adding a line should solve this issue. @davepagurek thoughts on this? @eyaler, Meanwhile mousePressed function can be used as a workaround.

p5.prototype._ontouchstart = function(e) {
  const context = this._isGlobal ? window : this;
  let executeDefault;
  this._setProperty('mouseIsPressed', true);
  this._updateTouchCoords(e);
  this._updateNextMouseCoords(e);
  this._updateMouseCoords(); // reset pmouseXY at the start of each touch event


  if (typeof context.touchStarted === 'function') {
    executeDefault = context.touchStarted(e);
    if (executeDefault === false) {
      e.preventDefault();
    }

@eyaler
Copy link
Author

eyaler commented Dec 1, 2024

@wayneharish10 thanks! Due to #7195 I cannot use mousePressed(). IIUC, it would only be called on release for short click and not at all for long press. I am actually calling mousePressed() my self from touchStart() to overcome that, and allow a unified interface.

@davepagurek
Copy link
Contributor

This looks like something that might get resolved in p5 2.0 due to this change #7378 which handles both mouse and touch events using the browser's pointer API rather than trying to handle both separately.

@wayneharish10
Copy link

Thanks @davepagurek. Saw the changes made in #7378 myself and I think it'll do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants