mosra / magnum

Lightweight and modular C++11 graphics middleware for games and data visualization
https://magnum.graphics/
Other
4.74k stars 439 forks source link

keyReleaseEvent not triggered after printscreen on OSX #622

Closed jvannugteren closed 3 months ago

jvannugteren commented 1 year ago

Hi Mosra, In OSX the keybind for making a screenshot of a section of the screen is: cmnd + shift + 5. When I do this the keyReleaseEvent is not triggered leaving shift and cmnd pressed forever (or until cmnd + shift is pressed again without screenshot). This can easily be verified in the IMGUI demo. Go to the "Inputs and Focus" section and make a screenshot using the keyboard shortcut, while the window is active. The "keys down" will show that the shift and cmnd keys are not released. I'm using an SDL2 application platform. Thanks in advance for having a look.

mosra commented 1 year ago

Hi,

I vaguely remember that various other people had this problem too, and IIRC it has something to do with how the OS treats this. Here's a similar bugreport for GLFW, from 2017: https://github.com/glfw/glfw/issues/1011

Unfortunately I wasn't able to find any such bugreport for SDL, but I suppose it's the same case. Not sure how to fix this apart from querying the key state directly, honestly. A somewhat related discussion is here: https://github.com/mosra/magnum-integration/issues/99

jvannugteren commented 1 year ago

Hmm yes it is exactly the same as the GLFW issue you mention. Indeed cmnd-shift-3 does not cause any issues (only cmnd-shift-5). I think OSX opening a screenshot UI steals away focus from the application and then forgets to send the keyReleaseEvent. So its an Apple issue? Maybe the screenshot triggers some event in SDL, for example window event, that allows me to override the ImGui keystate. Otherwise querying the keystate in each render loop may work as well. Feels a bit excessive though. I'll have a look.

jvannugteren commented 1 year ago

Another discovery. When the 5 gets pressed to finish the key combination, the keyPressEvent is not called either.

jvannugteren commented 3 months ago

This issue has fixed itself. Thanks.

mosra commented 3 months ago

Nice. Are you able trace that fix to a SDL commit, just in case someone else hits a similar problem?

jvannugteren commented 3 months ago

Not easy to find. Might also have been a MacOS update that fixed it. I'll keep searching.