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

Modifier keys remain in pressed state after triggering screen snipping function #1011

Open
jhauberg opened this issue May 10, 2017 · 4 comments · May be fixed by #2429
Open

Modifier keys remain in pressed state after triggering screen snipping function #1011

jhauberg opened this issue May 10, 2017 · 4 comments · May be fixed by #2429
Labels
bug Bug reports and bugfix pull requests macOS verified Reproduced or otherwise verified bugs
Milestone

Comments

@jhauberg
Copy link

OS: MacOS 10.12.4
GLFW Version: GLFW 3.3.0 Cocoa NSGL

When I trigger the MacOS screen snipping function (shift-cmd-4 or shift-cmd-4+space), then glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) and glfwGetKey(window, GLFW_KEY_LEFT_SUPER) will continuously report GLFW_PRESS each frame.

I've found two ways to reset the key state:

  1. Pressing each key once
  2. Having the window lose and then regain focus (it's not enough just clicking the window- it likely already has focus)
@dmitshur dmitshur added the macOS label May 11, 2017
@dmitshur
Copy link
Collaborator

Do you know if that happens only when doing a screenshot, or does it also happen if the window loses focus in any other way?

@jhauberg
Copy link
Author

jhauberg commented May 11, 2017

I can't think of a way to make it lose focus and get back to the window without letting it regain focus (which fixes said issue)...
Also note that the fullscreen screenshot function (shift-cmd-3) does not cause any problems.

@elmindreda elmindreda added the bug Bug reports and bugfix pull requests label May 11, 2017
@elmindreda elmindreda added the verified Reproduced or otherwise verified bugs label Aug 23, 2017
@elmindreda elmindreda changed the title Modifier keys remain in pressed state after triggering MacOS screen snipping function Modifier keys remain in pressed state after triggering screen snipping function Aug 23, 2017
@elmindreda elmindreda added this to the 3.4 milestone Oct 1, 2017
@bear24rw
Copy link

bear24rw commented Nov 7, 2023

Before the screenshot is taken flagsChanged is called once for each modifier key as they are being pressed in sequence by the user preforming the screenshot chord, then after the screenshot is taken flagsChanged gets called once but the key is a and the mods are cleared out. We then only call _glfwInputKey once, we probably should be calling it for each mod key so that they can get marked as released?

@bear24rw
Copy link

bear24rw commented Nov 7, 2023

So I "fixed" it with this insanely ugly patch but I'm not sure a better way to do this other than just emit events for every modifier every time.

diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 6f8aa978..0ea3209c 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -586,6 +586,15 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
         action = GLFW_RELEASE;

     _glfwInputKey(window, key, [event keyCode], action, mods);
+
+    _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT   , _glfw.ns.scancodes[GLFW_KEY_LEFT_SHIFT   ], mods & GLFW_MOD_SHIFT   ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_LEFT_CONTROL , _glfw.ns.scancodes[GLFW_KEY_LEFT_CONTROL ], mods & GLFW_MOD_CONTROL ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_LEFT_ALT     , _glfw.ns.scancodes[GLFW_KEY_LEFT_ALT     ], mods & GLFW_MOD_ALT     ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_LEFT_SUPER   , _glfw.ns.scancodes[GLFW_KEY_LEFT_SUPER   ], mods & GLFW_MOD_SUPER   ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT  , _glfw.ns.scancodes[GLFW_KEY_RIGHT_SHIFT  ], mods & GLFW_MOD_SHIFT   ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_RIGHT_CONTROL, _glfw.ns.scancodes[GLFW_KEY_RIGHT_CONTROL], mods & GLFW_MOD_CONTROL ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_RIGHT_ALT    , _glfw.ns.scancodes[GLFW_KEY_RIGHT_ALT    ], mods & GLFW_MOD_ALT     ? GLFW_PRESS : GLFW_RELEASE, mods);
+    _glfwInputKey(window, GLFW_KEY_RIGHT_SUPER  , _glfw.ns.scancodes[GLFW_KEY_RIGHT_SUPER  ], mods & GLFW_MOD_SUPER   ? GLFW_PRESS : GLFW_RELEASE, mods);
 }

 - (void)keyUp:(NSEvent *)event

flagsChanged.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports and bugfix pull requests macOS verified Reproduced or otherwise verified bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants