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

[PATCH] window created by SDL_CreateWindow doesn't handle ALT+anykey correctly on windows (=beeps) #1590

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.3
Reported for operating system, platform: Windows 7, x86

Comments on the original bug report:

On 2014-08-03 18:06:24 +0000, abma wrote:

SDL created windows seems to not correctly handle the key-combination ALT+C for example. when pressing this combination, windows plays the default system sound.

seems to happen only on windows:

https://gist.github.com/abma/a722346b7ad601d17ee8

On 2014-08-03 18:06:54 +0000, abma wrote:

this didn't happen with SDL1

On 2014-08-03 20:15:54 +0000, abma wrote:

SDL1:
https://github.com/spurious/SDL-mirror/blob/release-1.2.15/src/video/windib/SDL_dibevents.c#L271

"return 0"

vs

https://github.com/spurious/SDL-mirror/blob/f8662b28634522fe409d5e7c8a7d0d5fc894e7cf/src/video/windows/SDL_windowsevents.c#L570

returnCode = 0;
-> return CallWindowProc

(not sure if correct, but it very likely looks like a bug as behaviour changed)

On 2014-08-04 23:26:16 +0000, abma wrote:

this is the same report as # 865 it seems which was fixed but broken again...

On 2014-08-04 23:41:20 +0000, abma wrote:

this fixed # 865

https://hg.libsdl.org/SDL/rev/4384

On 2014-09-16 18:26:57 +0000, historic_bruno wrote:

I'm not certain this is a bug, though it is surely annoying. But for example, the same beep occurs in Visual Studio and some other window programs, when an invalid menu accelerator combo is used. Windows is quite noisy, which is why I mute all these sounds, but anyway...

I used Spy++ to see what kind of events were getting passed around my SDL2 window. The one that causes this beep as far as I can tell is WM_MENUCHAR, and according to MSDN if its handler returns a 0 (MNC_IGNORE) it will beep: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646349%28v=vs.85%29.aspx

I tried a quick hack in SDL to handle this message by returning MNC_CLOSE, but it had no effect, maybe I can't override this in the app? To confirm my suspicion, I removed the WS_SYSMENU style flag from SDL2's normal window style, and - no beep! but no system menu either.

Someone with more Windows API experience should look and see if something else is going wrong or if there's a good way to handle this.

On 2014-09-21 18:06:48 +0000, historic_bruno wrote:

Created attachment 1874
Handle the WM_MENUCHAR message to stop the beeping when Alt modifier key is used

On 2014-09-21 18:08:52 +0000, historic_bruno wrote:

Found more information about this from MS: http://support.microsoft.com/kb/92527

And that led me to a solution, I wasn't constructing the LRESULT properly in my last test. The attached patch stops the beep in an SDL window when Alt+[key] is used. One thing I still notice is the mouse cursor briefly flickers to the default cursor from my application's custom one, which occurred before the patch and may be related.

On 2015-01-02 16:16:09 +0000, abma wrote:

patch works for me, i'll get (hopefully) some more feedback from

http://springrts.com/mantis/view.php?id=4442

soon.

On 2015-01-12 04:30:25 +0000, abma wrote:

I still notice is the mouse cursor briefly flickers to the default cursor from my application's custom one, which occurred before the patch and may be related.

this happens for me, too but it happened already before the patch, so no big deal. but thats imo a slightly different bug.

the beep seems fixed by this patch, others verified that, too. thanks for helping!

On 2015-01-24 03:21:05 +0000, wrote:

The correct fix for this is to handle the WM_SYSCOMMAND SC_KEYMENU and return similar to how SDL2 currently eats SC_SCREENSAVE / SC_MONITORPOWER

Located https://hg.libsdl.org/SDL/file/8d826bc39a45/src/video/windows/SDL_windowsevents.c#l795

compare wParam & 0xFFF0 and if it is equal to SC_KEYMENU, return 0 (or optionally add a flag like the screensaver though default to true maybe?

This bug is same as # 865, reporting there as well.

On 2015-02-20 04:48:38 +0000, historic_bruno wrote:

Created attachment 2037
Handle the SC_KEYMENU message to stop the beeping when Alt modifier key is used

Alternative solution proposed by ensiform@gmail.com, prevents the beep but also stops the cursor flicker seen in the previous patch.

On 2015-02-22 15:04:21 +0000, wrote:

Does it need the ifdef SC_KEYMENU like the other two or is it supported much older than the other two SC_ defines?

On 2015-02-22 20:31:37 +0000, historic_bruno wrote:

(In reply to ensiform from comment # 12)

Does it need the ifdef SC_KEYMENU like the other two or is it supported much
older than the other two SC_ defines?

I wondered, but the only documentation I've found from MS is that WM_SYSCOMMAND is supported on Windows 2000 or later. According to https://wiki.libsdl.org/Installation#Windows_95.2F98.2FME and https://wiki.libsdl.org/FAQWindows even Windows 2000 is no longer a supported platform for SDL 2.0.

On 2015-04-07 04:57:53 +0000, Ryan C. Gordon wrote:

(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.

On 2015-05-26 15:09:34 +0000, Ryan C. Gordon wrote:

This patch is now https://hg.libsdl.org/SDL/rev/c5e1c4b7b7a1, thanks!

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant