mosra/magnum

keyReleaseEvent not triggered after printscreen on OSX

jvannugteren opened this issue · 6 comments

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

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: glfw/glfw#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: mosra/magnum-integration#99

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.

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

This issue has fixed itself. Thanks.

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

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