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

MouseEvent.getModifiers() not consistent between different renderers #3828

Closed
nakednous opened this issue Sep 19, 2015 · 6 comments
Closed
Assignees

Comments

@nakednous
Copy link

  • What steps will reproduce the problem?

Run the following sketch using different renderers (e.g., JAVA2D, P2D and P3D), and press the mouse (and some modifier keys if you like) and have a look at the output:

void setup() {
  size(640, 360, JAVA2D);
  fill(204);
  registerMethod("mouseEvent", this);
}

void draw() {
  background(0);
}

public void mouseEvent(processing.event.MouseEvent e) {
  switch (e.getAction()) {
  case MouseEvent.PRESS:
    String button = new String();
    if (e.getButton() == PApplet.RIGHT)
      button = "RIGHT ";
    else if (e.getButton() == PApplet.LEFT)
      button = "LEFT ";
    else if (e.getButton() == PApplet.CENTER)
      button = "CENTER ";
    println("Button: " + button +
      ", modifiers: " +
      getModifiersText(e.getModifiers()));
    break;
  default:
    break;
  }
}

public static String getModifiersText(int mask) {
  String r = new String();
  if ((Event.ALT & mask) == Event.ALT) r += "ALT";            
  if ((Event.SHIFT & mask) == Event.SHIFT) r += (r.length() > 0) ? "+SHIFT" : "SHIFT";
  if ((Event.CTRL & mask) == Event.CTRL) r += (r.length() > 0) ? "+CTRL" : "CTRL";
  if ((Event.META & mask) == Event.META) r += (r.length() > 0) ? "+META" : "META";
  return r;
}
  • What is the expected output?

Same mouse reports independently of the renderer.

  • What do you see instead?

Different reports.

  • What version of the product are you using?

P5-3.0-b6

  • On what operating system?

ArchLinux-x64.

  • Please provide any additional information below

This issue probably has to do with how events are handled differently by jogl and java (see #1693) which should be consistent (libraries supporting different renderers may be affected otherwise). A possible workaround would be to filter java events to match jogl output which IMO does it correctly.

@JakubValtar
Copy link
Contributor

This looks like a Linux problem, because I'm not able to reproduce it on Windows.

Could you please describe what is wrong with your output? Are you getting no modifiers, or different modifiers? Maybe a short example output?

@nakednous
Copy link
Author

When pressing left, center, and right mouse buttons without pressing any modifier key in Linux I got:

  • Java2D Linux
    Button: LEFT , modifiers:
    Button: CENTER , modifiers: ALT
    Button: RIGHT , modifiers: META
  • P2D/P3D Linux
    Button: LEFT , modifiers:
    Button: CENTER , modifiers:
    Button: RIGHT , modifiers:

I think all renderers should give the same results so that third-parties can consistently (and in an easy way) implement mouse events. I've implemented sort of a hack to deal with this issue in the past: you may refer to the Scene.p5ButtonModifiersFix here. Maybe it can be useful.

@nakednous
Copy link
Author

please let me know if more details are needed....

@benfry
Copy link
Contributor

benfry commented Sep 29, 2015

This is just a duplicate of your earlier issue #1693 where I also tried to explain the different behavior.

This isn't something that can be "fixed" in a way that's consistent across platforms. The practical application, and the one that can work consistently is that you'll get the correct value for the button (LEFT, CENTER, or RIGHT), but you can't mix modifiers with those because each OS handles those differently.

For instance, a ctrl-left-click on OS X triggers the right mouse button. You can't distinguish that from an actual right mouse click that also has control pressed on OS X. So while we could hide that behavior further, the result would be running into "bugs" later in the process, when you tried to run code that depended on that behavior on OS X. Same goes for several of these other variants. Bottom line, relying on awkward key + mouse behaviors like this is simply bad practice, and you're better served by pursuing an alternate approach.

@nakednous
Copy link
Author

is ok with me to remove the modifiers from mouse bindings. Didn't know about the OS X behavior... Thank you :)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants