diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index c76722316..dded757bc 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -1780,6 +1780,7 @@ typedef enum { EVENTFLAG_IS_KEY_PAD = 1 << 9, EVENTFLAG_IS_LEFT = 1 << 10, EVENTFLAG_IS_RIGHT = 1 << 11, + EVENTFLAG_ALTGR_DOWN = 1 << 12, } cef_event_flags_t; /// diff --git a/libcef/browser/native/browser_platform_delegate_native_aura.cc b/libcef/browser/native/browser_platform_delegate_native_aura.cc index e036c98ea..db5ceb1ea 100644 --- a/libcef/browser/native/browser_platform_delegate_native_aura.cc +++ b/libcef/browser/native/browser_platform_delegate_native_aura.cc @@ -210,6 +210,8 @@ int CefBrowserPlatformDelegateNativeAura::TranslateUiEventModifiers( result |= ui::EF_CAPS_LOCK_ON; if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON) result |= ui::EF_NUM_LOCK_ON; + if (cef_modifiers & EVENTFLAG_ALTGR_DOWN) + result |= ui::EF_ALTGR_DOWN; return result; } diff --git a/libcef/browser/native/browser_platform_delegate_native_linux.cc b/libcef/browser/native/browser_platform_delegate_native_linux.cc index cd8ef7e61..b6364b2f0 100644 --- a/libcef/browser/native/browser_platform_delegate_native_linux.cc +++ b/libcef/browser/native/browser_platform_delegate_native_linux.cc @@ -313,6 +313,16 @@ ui::KeyEvent CefBrowserPlatformDelegateNativeLinux::TranslateUiKeyEvent( return ui::KeyEvent(type, key_code, dom_code, flags, dom_key, time_stamp); } +content::NativeWebKeyboardEvent +CefBrowserPlatformDelegateNativeLinux::TranslateWebKeyEvent( + const CefKeyEvent& key_event) const { + ui::KeyEvent ui_event = TranslateUiKeyEvent(key_event); + if (key_event.type == KEYEVENT_CHAR) { + return content::NativeWebKeyboardEvent(ui_event, key_event.character); + } + return content::NativeWebKeyboardEvent(ui_event); +} + base::TimeTicks CefBrowserPlatformDelegateNativeLinux::GetEventTimeStamp() const { return base::TimeTicks() + base::TimeDelta::FromSeconds(GetSystemUptime()); diff --git a/libcef/browser/native/browser_platform_delegate_native_linux.h b/libcef/browser/native/browser_platform_delegate_native_linux.h index 96ee95a76..7f1834a3d 100644 --- a/libcef/browser/native/browser_platform_delegate_native_linux.h +++ b/libcef/browser/native/browser_platform_delegate_native_linux.h @@ -40,6 +40,8 @@ class CefBrowserPlatformDelegateNativeLinux // CefBrowserPlatformDelegateNativeAura methods: ui::KeyEvent TranslateUiKeyEvent(const CefKeyEvent& key_event) const override; + content::NativeWebKeyboardEvent TranslateWebKeyEvent( + const CefKeyEvent& key_event) const override; base::TimeTicks GetEventTimeStamp() const override; private: diff --git a/tests/cefclient/browser/osr_window_win.cc b/tests/cefclient/browser/osr_window_win.cc index 1be90d78d..66b220d05 100644 --- a/tests/cefclient/browser/osr_window_win.cc +++ b/tests/cefclient/browser/osr_window_win.cc @@ -791,6 +791,25 @@ void OsrWindowWin::OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam) { event.type = KEYEVENT_CHAR; event.modifiers = GetCefKeyboardModifiers(wParam, lParam); + // mimic alt-gr check behaviour from + // src/ui/events/win/events_win_utils.cc: GetModifiersFromKeyState + if ((event.type == KEYEVENT_CHAR) && IsKeyDown(VK_RMENU)) { + // reverse AltGr detection taken from PlatformKeyMap::UsesAltGraph + // instead of checking all combination for ctrl-alt, just check current char + HKL current_layout = ::GetKeyboardLayout(0); + + // https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-vkkeyscanexw + // ... high-order byte contains the shift state, + // which can be a combination of the following flag bits. + // 2 Either CTRL key is pressed. + // 4 Either ALT key is pressed. + SHORT scan_res = ::VkKeyScanExW(wParam, current_layout); + if (((scan_res >> 8) & 0xFF) == (2 | 4)) { // ctrl-alt pressed + event.modifiers &= ~(EVENTFLAG_CONTROL_DOWN | EVENTFLAG_ALT_DOWN); + event.modifiers |= EVENTFLAG_ALTGR_DOWN; + } + } + browser_->GetHost()->SendKeyEvent(event); }