-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Comments
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! |
Hey, I would like to work on this bug, please! |
…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.
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. |
In the PR: #7378, setting mouseButton on fn._setMouseButton = function(e) {
// Using e.buttons bitmask to track which buttons are pressed
this.mouseButton.left = (e.buttons & 1) !== 0; // Left button
this.mouseButton.center = (e.buttons & 4) !== 0; // Middle button
this.mouseButton.right = (e.buttons & 2) !== 0; // Right button
}; |
I'm in favour of replacing the single variable with an object with Do those pointer move events that update the buttons also come attached to a specific pointer ID? I wonder if, in addition to a single global |
@diyaayay Would the proposed approach means that if there are only I haven't quite use this part of things directly very much before but perhaps the @davepagurek Pointer events do come with pointer ID so we can identify individual pointer. |
@limzykenneth Yes, that is what I've been seeing. So, for multiple mouse clicks only Instead, chorded button presses can be detected by inspecting changes to the button and buttons properties. The button and buttons properties are inherited from the MouseEvent interface, but with a change in semantics and values. |
Untitled.design.7.mp4For the sketch: function mousePressed() {
console.log(mouseButton);
}
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
} This is how |
I don't think so. |
An object sounds good to me, it lets us indicate when more than one button is pressed, which is something the current API isn't expressive enough for. |
https://editor.p5js.org/diya.solanki.31/sketches/KbLubzBoV Here is a sketch that shows the same. |
Most appropriate sub-area of p5.js?
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:
left
right
Snippet:
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 tomouseButton
being updated inmousePressed
but notmouseReleased
.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.
The text was updated successfully, but these errors were encountered: