Skip to content

Commit a2b61f3

Browse files
deonberlinDaniel Bitterlich
andauthored
WPF - Implement AltGr support. (#3131)
* Fixed #3104 AltGr support. * Code format adjusted. * Moved AltGr code to better location within the function. Co-authored-by: Daniel Bitterlich <[email protected]>
1 parent 2a62f97 commit a2b61f3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

CefSharp.Core/Internals/CefBrowserHostWrapper.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ void CefBrowserHostWrapper::SendKeyEvent(int message, int wParam, int lParam)
286286
keyEvent.is_system_key = message == WM_SYSCHAR ||
287287
message == WM_SYSKEYDOWN ||
288288
message == WM_SYSKEYUP;
289+
keyEvent.modifiers = GetCefKeyboardModifiers(wParam, lParam);
289290

290291
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
291292
{
@@ -298,9 +299,29 @@ void CefBrowserHostWrapper::SendKeyEvent(int message, int wParam, int lParam)
298299
else
299300
{
300301
keyEvent.type = KEYEVENT_CHAR;
301-
}
302-
keyEvent.modifiers = GetCefKeyboardModifiers(wParam, lParam);
303302

303+
// mimic alt-gr check behaviour from
304+
// src/ui/events/win/events_win_utils.cc: GetModifiersFromKeyState
305+
if (IsKeyDown(VK_RMENU))
306+
{
307+
// reverse AltGr detection taken from PlatformKeyMap::UsesAltGraph
308+
// instead of checking all combination for ctrl-alt, just check current char
309+
HKL current_layout = ::GetKeyboardLayout(0);
310+
311+
// https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-vkkeyscanexw
312+
// ... high-order byte contains the shift state,
313+
// which can be a combination of the following flag bits.
314+
// 2 Either CTRL key is pressed.
315+
// 4 Either ALT key is pressed.
316+
SHORT scan_res = ::VkKeyScanExW(wParam, current_layout);
317+
if (((scan_res >> 8) & 0xFF) == (2 | 4)) // ctrl-alt pressed
318+
{
319+
keyEvent.modifiers &= ~(EVENTFLAG_CONTROL_DOWN | EVENTFLAG_ALT_DOWN);
320+
keyEvent.modifiers |= EVENTFLAG_ALTGR_DOWN;
321+
}
322+
}
323+
}
324+
304325
_browserHost->SendKeyEvent(keyEvent);
305326
}
306327

0 commit comments

Comments
 (0)