diff --git a/BeefLibs/Beefy2D/src/widgets/KeyCode.bf b/BeefLibs/Beefy2D/src/widgets/KeyCode.bf index 4369d2a3..74c32e7d 100644 --- a/BeefLibs/Beefy2D/src/widgets/KeyCode.bf +++ b/BeefLibs/Beefy2D/src/widgets/KeyCode.bf @@ -82,6 +82,8 @@ namespace Beefy.widgets F12 = 0x7B, Numlock = 0x90, Scroll = 0x91, + RAlt = 0xA5, + RMenu = 0xA5, Semicolon = 0xBA, Equals = 0xBB, Comma = 0xBC, diff --git a/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf b/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf index 5c434757..9aa86a93 100644 --- a/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf +++ b/BeefLibs/Beefy2D/src/widgets/WidgetWindow.bf @@ -121,7 +121,7 @@ namespace Beefy.widgets KeyFlags keyFlags = default; if (IsKeyDown(KeyCode.Shift)) keyFlags |= KeyFlags.Shift; - if (IsKeyDown(KeyCode.Control)) + if ((IsKeyDown(KeyCode.Control)) && (!IsKeyDown(KeyCode.RAlt))) keyFlags |= KeyFlags.Ctrl; if (IsKeyDown(KeyCode.Menu)) keyFlags |= KeyFlags.Alt; @@ -137,7 +137,7 @@ namespace Beefy.widgets { if (mRootWidget == null) return; - + base.Draw(g); mRootWidget.DrawAll(g); } diff --git a/BeefySysLib/platform/win/WinBFApp.cpp b/BeefySysLib/platform/win/WinBFApp.cpp index acb7159b..2208193c 100644 --- a/BeefySysLib/platform/win/WinBFApp.cpp +++ b/BeefySysLib/platform/win/WinBFApp.cpp @@ -76,6 +76,22 @@ static BOOL ClipToMonitor(HMONITOR mon, HDC hdc, LPRECT monRect, LPARAM userArg) return TRUE; } +static BOOL KeyboardLayoutHasAltGr(HKL layout) +{ + BOOL hasAltGr = FALSE; + int scancode; + for (WORD i = 32; i < 256; ++i) + { + scancode = VkKeyScanEx((TCHAR)i, layout); + if ((scancode != -1) && ((scancode & 0x600) == 0x600)) + { + hasAltGr = TRUE; + break; + } + } + return hasAltGr; +} + WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags) { HINSTANCE hInstance = GetModuleHandle(NULL); @@ -281,6 +297,9 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y BF_ASSERT(winParent->mHWnd); parent->mChildren.push_back(this); } + + HKL layout = GetKeyboardLayout(0); + mKeyLayoutHasAltGr = (KeyboardLayoutHasAltGr(layout) == TRUE); } WinBFWindow::~WinBFWindow() @@ -880,6 +899,9 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar if (keyCode == VK_APPS) break; // This is handled in WM_CONTEXTMENU + if ((mKeyLayoutHasAltGr) && (keyCode == VK_MENU) && ((lParam & 0x01000000) != 0)) + keyCode = VK_RMENU; + mIsKeyDown[keyCode] = true; for (auto kv : *menuIDMap) @@ -899,7 +921,7 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar if (!mIsMenuKeyHandled) { - if (mKeyDownFunc(this, (int) wParam, (lParam & 0x7FFF) != 0)) + if (mKeyDownFunc(this, keyCode, (lParam & 0x7FFF) != 0)) { mIsMenuKeyHandled = true; doResult = true; @@ -936,9 +958,11 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar case WM_KEYUP: { int keyCode = (int) wParam; + if ((mKeyLayoutHasAltGr) && (keyCode == VK_MENU) && ((lParam & 0x01000000) != 0)) + keyCode = VK_RMENU; if (mIsKeyDown[keyCode]) { - mKeyUpFunc(this, (int) wParam); + mKeyUpFunc(this, keyCode); mIsKeyDown[keyCode] = false; } } @@ -1023,6 +1047,10 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar if (gBFApp->mSysDialogCnt == 0) gBFApp->Process(); break; + + case WM_INPUTLANGCHANGE: + mKeyLayoutHasAltGr = (KeyboardLayoutHasAltGr((HKL)lParam) == TRUE); + break; } app->mInMsgProc = false; diff --git a/BeefySysLib/platform/win/WinBFApp.h b/BeefySysLib/platform/win/WinBFApp.h index ec9b8f3b..4948f7e0 100644 --- a/BeefySysLib/platform/win/WinBFApp.h +++ b/BeefySysLib/platform/win/WinBFApp.h @@ -52,6 +52,7 @@ public: bool mSoftHasFocus; // Mostly tracks mHasFocus except for when we get an explicit 'LostFocus' callback bool mNeedsStateReset; + bool mKeyLayoutHasAltGr; public: virtual LRESULT WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); diff --git a/IDE/src/ui/PropertiesDialog.bf b/IDE/src/ui/PropertiesDialog.bf index 6935ec5f..014dd468 100644 --- a/IDE/src/ui/PropertiesDialog.bf +++ b/IDE/src/ui/PropertiesDialog.bf @@ -44,7 +44,8 @@ namespace IDE.ui { if ((evt.mKeyCode == .Control) || (evt.mKeyCode == .Shift) || - (evt.mKeyCode == .Alt)) + (evt.mKeyCode == .Alt) || + (evt.mKeyCode == .RAlt)) return; if ((evt.mKeyFlags == 0) &&