diff --git a/src/editor/C4EditCursor.cpp b/src/editor/C4EditCursor.cpp index a1ac22fee..ba2f9a1d3 100644 --- a/src/editor/C4EditCursor.cpp +++ b/src/editor/C4EditCursor.cpp @@ -362,6 +362,8 @@ bool C4EditCursor::KeyDown(C4KeyCode KeyCode, DWORD dwKeyState) fShiftIsDown = fShiftIsDown || (kcx.ToString(false, false) == "Shift" || kcx.ToString(false, false) == "Shift_L" || kcx.ToString(false, false) == "Shift_R"); if(fShiftIsDown != fShiftWasDown) fShiftWasDown = fShiftIsDown; + + return true; } bool C4EditCursor::KeyUp(C4KeyCode KeyCode, DWORD dwKeyState) @@ -384,6 +386,8 @@ bool C4EditCursor::KeyUp(C4KeyCode KeyCode, DWORD dwKeyState) fShiftIsDown = fShiftIsDown && !(kcx.ToString(false, false) == "Shift" || kcx.ToString(false, false) == "Shift_L" || kcx.ToString(false, false) == "Shift_R"); if(fShiftIsDown != fShiftWasDown) fShiftWasDown = fShiftIsDown; + + return true; } #ifdef USE_WIN32_WINDOWS diff --git a/src/gui/C4KeyboardInput.cpp b/src/gui/C4KeyboardInput.cpp index 7702ca05a..9a4cb1c6a 100644 --- a/src/gui/C4KeyboardInput.cpp +++ b/src/gui/C4KeyboardInput.cpp @@ -121,7 +121,7 @@ const C4KeyCodeMapEntry KeyCodeMap [] = { VK_SHIFT , "KeyShift" , "Shift" }, { VK_CONTROL , "KeyControl" , "Control" }, - { VK_MENU , "Menu" , NULL }, + { VK_MENU , "Alt" , NULL }, { VK_PAUSE , "Pause" , NULL }, { VK_CAPITAL , "Capital" , NULL }, diff --git a/src/platform/C4App.h b/src/platform/C4App.h index 6e3d1c91a..3e4e46a30 100644 --- a/src/platform/C4App.h +++ b/src/platform/C4App.h @@ -50,6 +50,7 @@ extern int MK_SHIFT; extern int MK_CONTROL; extern int MK_ALT; #elif defined(USE_WIN32_WINDOWS) +#define MK_ALT 0x10000 // well beyond the pre-defined values #include #endif diff --git a/src/platform/C4ViewportWindow.cpp b/src/platform/C4ViewportWindow.cpp index 4d4f23ed7..e9771587e 100644 --- a/src/platform/C4ViewportWindow.cpp +++ b/src/platform/C4ViewportWindow.cpp @@ -208,7 +208,7 @@ void C4ViewportWindow::Close() { ::Viewports.CloseViewport(cvp); } -void C4ViewportWindow::EditCursorMove(int X, int Y, uint16_t state) +void C4ViewportWindow::EditCursorMove(int X, int Y, uint32_t state) { Console.EditCursor.Move(cvp->ViewX + X / cvp->Zoom, cvp->ViewY + Y / cvp->Zoom, state); } diff --git a/src/platform/C4ViewportWindow.h b/src/platform/C4ViewportWindow.h index c9db8fe53..bccdbceb1 100644 --- a/src/platform/C4ViewportWindow.h +++ b/src/platform/C4ViewportWindow.h @@ -42,7 +42,7 @@ public: GtkWidget* h_scrollbar; GtkWidget* v_scrollbar; #endif - void EditCursorMove(int X, int Y, uint16_t); + void EditCursorMove(int X, int Y, uint32_t); using C4Window::Init; C4Window * Init(int32_t iPlayer); virtual void Close(); diff --git a/src/platform/C4WindowWin32.cpp b/src/platform/C4WindowWin32.cpp index cbdb98e4b..cef57d78b 100644 --- a/src/platform/C4WindowWin32.cpp +++ b/src/platform/C4WindowWin32.cpp @@ -137,16 +137,16 @@ LRESULT APIENTRY FullScreenWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l Application.MusicSystem.NotifySuccess(); return true; case WM_KEYUP: - if (Game.DoKeyboardInput(wParam, KEYEV_Up, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), false, NULL)) + if (Game.DoKeyboardInput(wParam, KEYEV_Up, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, false, NULL)) return 0; break; case WM_KEYDOWN: - if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), !!(lParam & 0x40000000), NULL)) + if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, !!(lParam & 0x40000000), NULL)) return 0; break; case WM_SYSKEYDOWN: if (wParam == 18) break; - if (Game.DoKeyboardInput(wParam, KEYEV_Down, Application.IsAltDown(), Application.IsControlDown(), Application.IsShiftDown(), !!(lParam & 0x40000000), NULL)) + if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, !!(lParam & 0x40000000), NULL)) return 0; break; case WM_CHAR: @@ -230,19 +230,19 @@ LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - default: - if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), !!(lParam & 0x40000000), NULL)) return 0; + if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, !!(lParam & 0x40000000), NULL)) return 0; break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } break; //--------------------------------------------------------------------------------------------------------------------------- case WM_KEYUP: - if (Game.DoKeyboardInput(wParam, KEYEV_Up, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), false, NULL)) return 0; + if (Game.DoKeyboardInput(wParam, KEYEV_Up, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, false, NULL)) return 0; break; //------------------------------------------------------------------------------------------------------------ case WM_SYSKEYDOWN: if (wParam == 18) break; - if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), !!(lParam & 0x40000000), NULL)) return 0; + if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, !!(lParam & 0x40000000), NULL)) return 0; break; //---------------------------------------------------------------------------------------------------------------------------------- case WM_DESTROY: @@ -366,21 +366,41 @@ LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // Console edit cursor control else { + // The state of the ALT key is not reported in wParam for mouse messages, + // and for keyboard messages the key states are hidden in lParam. It's a mess. Let's just + // query GetKeyState(). + DWORD dwKeyState = 0; + if(GetKeyState(VK_CONTROL) < 0) dwKeyState |= MK_CONTROL; + if(GetKeyState(VK_SHIFT) < 0) dwKeyState |= MK_SHIFT; + if(GetKeyState(VK_MENU) < 0) dwKeyState |= MK_ALT; + switch (uMsg) { + case WM_KEYDOWN: + Console.EditCursor.KeyDown(wParam, dwKeyState); + break; + case WM_KEYUP: + Console.EditCursor.KeyUp(wParam, dwKeyState); + break; + case WM_SYSKEYDOWN: + Console.EditCursor.KeyDown(wParam, dwKeyState); + break; + case WM_SYSKEYUP: + Console.EditCursor.KeyUp(wParam, dwKeyState); + break; //---------------------------------------------------------------------------------------------------------------------------------- case WM_LBUTTONDOWN: // movement update needed before, so target is always up-to-date - cvp->pWindow->EditCursorMove(LOWORD(lParam), HIWORD(lParam), wParam); - Console.EditCursor.LeftButtonDown(wParam); break; + cvp->pWindow->EditCursorMove(LOWORD(lParam), HIWORD(lParam), dwKeyState); + Console.EditCursor.LeftButtonDown(dwKeyState); break; //---------------------------------------------------------------------------------------------------------------------------------- - case WM_LBUTTONUP: Console.EditCursor.LeftButtonUp(wParam); break; + case WM_LBUTTONUP: Console.EditCursor.LeftButtonUp(dwKeyState); break; //---------------------------------------------------------------------------------------------------------------------------------- - case WM_RBUTTONDOWN: Console.EditCursor.RightButtonDown(wParam); break; + case WM_RBUTTONDOWN: Console.EditCursor.RightButtonDown(dwKeyState); break; //---------------------------------------------------------------------------------------------------------------------------------- - case WM_RBUTTONUP: Console.EditCursor.RightButtonUp(wParam); break; + case WM_RBUTTONUP: Console.EditCursor.RightButtonUp(dwKeyState); break; //---------------------------------------------------------------------------------------------------------------------------------- - case WM_MOUSEMOVE: cvp->pWindow->EditCursorMove(LOWORD(lParam), HIWORD(lParam), wParam); break; + case WM_MOUSEMOVE: cvp->pWindow->EditCursorMove(LOWORD(lParam), HIWORD(lParam), dwKeyState); break; //---------------------------------------------------------------------------------------------------------------------------------- } } @@ -399,16 +419,16 @@ LRESULT APIENTRY DialogWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara { //--------------------------------------------------------------------------------------------------------------------------- case WM_KEYDOWN: - if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), !!(lParam & 0x40000000), pDlg)) return 0; + if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, !!(lParam & 0x40000000), pDlg)) return 0; break; //--------------------------------------------------------------------------------------------------------------------------- case WM_KEYUP: - if (Game.DoKeyboardInput(wParam, KEYEV_Up, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), false, pDlg)) return 0; + if (Game.DoKeyboardInput(wParam, KEYEV_Up, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, false, pDlg)) return 0; break; //------------------------------------------------------------------------------------------------------------ case WM_SYSKEYDOWN: if (wParam == 18) break; - if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), Application.IsControlDown(), Application.IsShiftDown(), !!(lParam & 0x40000000), pDlg)) return 0; + if (Game.DoKeyboardInput(wParam, KEYEV_Down, !!(lParam & 0x20000000), GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0, !!(lParam & 0x40000000), pDlg)) return 0; break; //---------------------------------------------------------------------------------------------------------------------------------- case WM_DESTROY: