Skip to content

Commit

Permalink
JBR-7336 Any keyboard shortcut with Alt produces a Windows system sound.
Browse files Browse the repository at this point in the history
fixup! JBR-7157: Alt+Shift+Enter sends KEY_TYPED Event.

Consume all WM_SYSCHAR messages (except for the Alt+Space keystroke), not allowing them to reach the system default handling routine, so the last won't make system beeps anymore after any [Shift+]Alt+<digit/letter> keystroke.

(cherry picked from commit 5d0e304)
(cherry picked from commit d433cc6)
  • Loading branch information
NikitkoCent authored and vprovodin committed Jun 26, 2024
1 parent b25af5b commit 9fc3a38
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/java.desktop/windows/native/libawt/windows/awt_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,14 +1874,8 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
LOWORD(lParam), HIWORD(lParam), FALSE);
break;
case WM_SYSCHAR:
// JBR-7157: Alt+Shift+Enter sends KEY_TYPED Event
// Alt[+Shift]+letter generate input only as WM_SYSCHAR messages.
// We shouldn't treat them as real user input, according to MSDN: https://learn.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input#character-messages.
// > The WM_SYSCHAR message indicates a system character. As with WM_SYSKEYDOWN, you should generally pass
// > this message directly to DefWindowProc. Otherwise, you may interfere with standard system commands.
// > In particular, do not treat WM_SYSCHAR as text that the user has typed.

mr = mrDoDefault;
mr = WmChar(static_cast<UINT>(wParam),
LOWORD(lParam), HIWORD(lParam), TRUE);
break;
case WM_IME_CHAR:
mr = WmIMEChar(static_cast<UINT>(wParam),
Expand Down Expand Up @@ -3977,13 +3971,27 @@ MsgRouting AwtComponent::WmChar(UINT character, UINT repCnt, UINT flags,
// i.e., it is the 13th bit of `flags' (which is HIWORD(lParam)).
bool alt_is_down = (flags & (1<<13)) != 0;

// Fix for bug 4141621, corrected by fix for bug 6223726: Alt+space doesn't invoke system menu
// We should not pass this particular combination to Java.

if (system && alt_is_down) {
if (character == VK_SPACE) {
if (system) {
// Fix for bug 4141621, corrected by fix for bug 6223726: Alt+space doesn't invoke system menu
// We should not pass this particular combination to Java.
if ( alt_is_down && (character == VK_SPACE) ) {
return mrDoDefault;
}

// JBR-7157: Alt+Shift+Enter sends KEY_TYPED Event.
// Alt[+Shift]+letter generate input only as WM_SYSCHAR messages.
// We shouldn't treat them as real user input, according to MSDN: https://learn.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input#character-messages.
// > The WM_SYSCHAR message indicates a system character. As with WM_SYSKEYDOWN, you should generally pass
// > this message directly to DefWindowProc. Otherwise, you may interfere with standard system commands.
// > In particular, do not treat WM_SYSCHAR as text that the user has typed.
// In other words, we shouldn't generate KEY_TYPED events for WM_SYSCHAR messages.

// You can find below how the field is used, let's reset the state just-in-case.
m_PendingLeadByte = 0;

// JBR-7336 Any keyboard shortcut with Alt produces a Windows system sound.
// mrDoDefault here would lead to system beeps after any [Shift+]Alt+<letter/digit> keystrokes.
return mrConsume;
}

// If this is a WM_CHAR (non-system) message, then the Alt flag
Expand Down

0 comments on commit 9fc3a38

Please sign in to comment.