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
Right mousebutton click #36
Comments
No support just yet, will need to add that to the interaction manager 👍 |
Honestly I think the best way to do this would be to pass along event information for mouse events. Then you can do it properly on Something like: var lastClick = 0,
space = 350;
sprite.click = function(data) {
var now = Date.now(),
diff = now - lastClick;
event = data.originalEvent;
if(event.which === 3 || event.button === 2) {
//this was a right click;
} else if(lastClick && (diff < space)) {
lastClick = 0; //reset time
//this was a double click
} else {
lastClick = now; //update last click time
//this was a regular click
}
}; I'll see if I can't get something going this weekend on this. |
Please nte that the code example I changed slightly, decided to put the original event in the InteractionData object. |
The original event does not work for me in Chrome (Version 32.0.1700.102 m). The "button" and "which" parameters are always 0. When I attach a simple listener like this it works:
|
@misters Do you have a live example, or simple code example I can look at? Thanks! |
I will see if I can work out an example tomorrow. |
@misters That should be fine, thanks for the extra info. That is a really strange one! |
Has there been any solution to the e.which, e.button always being 0? They are still always 0 for me as well. Also, the "type" is also mousemove, even when I right click. |
I'm not able to reproduce this, so I will need to see some code like I mentioned before. Using the following it works fine:
The output I get from a left-click is:
And from a right-click is:
|
Is there any reason why this is not in the main PIXI? (the right click differentiation) I ask because I was planning to add it, and maybe there were complications that I couldn't see and maybe end up losing a lot of time. Thanks |
It is supported by the native browser what are we going to do to make it easier than what the native browser provides? |
I meant, right and left click over an image. For what I know, the browser identifies clicks over the canvas only. That is why PIXI does a collision test with every interactive image. This: for (var i = 0; i < length; i++) {
var item = this.interactiveItems[i];
if (item.mousedown || item.click) {
item.__mouseIsDown = true;
item.__hit = this.hitTest(item, this.mouse);
if (item.__hit) {
//call the function!
if (item.mousedown)item.mousedown(this.mouse);
item.__isDown = true;
// just the one!
if (!item.interactiveChildren)break;
}
}
} There is no button distinction, so all collisions will be checked even if that is not the button you wanted to listen to. My idea was doing something like this: var event = this.mouse.originalEvent;
var isRightButton = event.button === 2 || event.which === 3; And then testing for different buttons in a similar way to the original code. if ( !isRightButton && (item.mousedown || item.click) ) {
//Code for the left click, same code as the original
}
else if ( isRightButton && (item.rightdown || item.rightclick) ) {
//Right click code
item.__IsRightDown = true;
item.__hit = this.hitTest(item, this.mouse);
if (item.__hit) {
//call the function!
if (item.rightdown)item.rightdown(this.mouse);
item.__isRightDown = true;
// just the one!
if (!item.interactiveChildren)break;
}
} The benefits of this are:
|
+1 |
So it is for the purpose of optimization. I could see that, feel free to throw in a PR. |
Thanks! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi. I can’t catch, how to detect if right mouse button was clicked?
Or how to detect double-click?
The text was updated successfully, but these errors were encountered: