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 contains incorrect value after pressing both mouse buttons and releasing one of them #6847

Open
1 of 17 tasks
servobot opened this issue Mar 12, 2024 · 3 comments · May be fixed by #6943
Open
1 of 17 tasks

Comments

@servobot
Copy link

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

Web browser and version

122.0.6261.95 (Official Build) (64-bit) (cohort: Stable)

Operating system

Windows 10 Home Edition

Steps to reproduce this

Steps:

  1. Press and hold left mouse button
  2. Press and hold right mouse button
  3. Release left mouse button
    • Expected: console logs left
    • Actual: console logs right

Snippet:

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

function mouseReleased() {
  console.log(mouseButton);
}

function draw() {
  background(220);
}

Additional Context

I discovered this issue when implementing the game of Minesweeper. In that game, pressing and releasing both mouse buttons at the same time is the way to uncover all unmarked neighbors of a cell, and I found that I could not detect this condition reliably using mouseButton. I believe this is due to mouseButton being updated in mousePressed but not mouseReleased.

https://github.com/processing/p5.js/blob/main/src/events/mouse.js#L657
https://github.com/processing/p5.js/blob/main/src/events/mouse.js#L733

I have a pull request (with associated unit test) that appears to resolve the issue. This bug was previously reported in #5733, but the submitter resolved that issue as they found a workaround.

@servobot servobot added the Bug label Mar 12, 2024
Copy link

welcome bot commented Mar 12, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@Renatolo
Copy link

Renatolo commented Apr 4, 2024

Hey, I would like to work on this bug, please!

Renatolo added a commit to Renatolo/p5.js that referenced this issue Apr 5, 2024
…s released

- Modified src/events/mouse.js to correctly update the mouseButton value upon releasing one mouse button.
- Updated documentation in src/events/mouse.js accordingly.
- Added unit test in test/unit/events/mouse.js to cover scenario described in the issue.
@limzykenneth
Copy link
Member

This is more or less intended behavior documented and I'm not keen to change the behavior. There is probably room to have better support for simultaneous mouse button presses as currently having the context menu being brought up by the right mouse button can confuse things often.

There is a larger proposal here for better mouse event handling that I think can be explored in p5.js 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants