From: <sv...@op...> - 2024-04-03 18:27:33
|
Author: sagamusix Date: Wed Apr 3 20:27:21 2024 New Revision: 20490 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20490 Log: [Ref] Add harder-to-misuse overload for CInputHandler::GetKeyEventType. Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/InputHandler.h trunk/OpenMPT/mptrack/view_com.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp Wed Apr 3 20:24:00 2024 (r20489) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp Wed Apr 3 20:27:21 2024 (r20490) @@ -95,11 +95,8 @@ //The key was not handled by a command, but it might still be useful if (pMsg->message == WM_CHAR) //key is a character { - UINT nFlags = HIWORD(pMsg->lParam); - KeyEventType kT = CMainFrame::GetInputHandler()->GetKeyEventType(nFlags); - - if (kT == kKeyEventDown) - if (HandleChar(wParam)) + if(CInputHandler::GetKeyEventType(*pMsg) == kKeyEventDown) + if(HandleChar(wParam)) return true; } else if (pMsg->message == WM_KEYDOWN) //key is not a character Modified: trunk/OpenMPT/mptrack/InputHandler.cpp ============================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp Wed Apr 3 20:24:00 2024 (r20489) +++ trunk/OpenMPT/mptrack/InputHandler.cpp Wed Apr 3 20:27:21 2024 (r20490) @@ -348,6 +348,12 @@ } +KeyEventType CInputHandler::GetKeyEventType(const MSG &msg) +{ + return GetKeyEventType(HIWORD(msg.lParam)); +} + + KeyEventType CInputHandler::GetKeyEventType(UINT nFlags) { if (nFlags & TRANSITIONBIT) @@ -637,9 +643,11 @@ if(!GetModifierMask().test_any_except(ModShift)) { if((key >= 'A' && key <= 'Z') || (key >= '0' && key <= '9') - || key == VK_DIVIDE || key == VK_MULTIPLY || key == VK_SPACE || key == VK_CAPITAL + || (key >= VK_MULTIPLY && key <= VK_DIVIDE) || key == VK_SPACE || key == VK_CAPITAL || (key >= VK_OEM_1 && key <= VK_OEM_3) || (key >= VK_OEM_4 && key <= VK_OEM_8)) return true; + if((key >= VK_NUMPAD0 && key <= VK_NUMPAD9) && GetModifierMask() == ModNone) + return true; if(key == VK_RETURN && (GetWindowLong(hWnd, GWL_STYLE) & ES_MULTILINE)) return true; } Modified: trunk/OpenMPT/mptrack/InputHandler.h ============================================================================== --- trunk/OpenMPT/mptrack/InputHandler.h Wed Apr 3 20:24:00 2024 (r20489) +++ trunk/OpenMPT/mptrack/InputHandler.h Wed Apr 3 20:27:21 2024 (r20490) @@ -52,6 +52,7 @@ CommandID GeneralKeyEvent(InputTargetContext context, int code, WPARAM wParam, LPARAM lParam); CommandID KeyEvent(const InputTargetContext context, const KeyboardEvent &event, CWnd *pSourceWnd = nullptr); static KeyboardEvent Translate(const MSG &msg); + static KeyEventType GetKeyEventType(const MSG &msg); static KeyEventType GetKeyEventType(UINT nFlags); bool IsKeyPressHandledByTextBox(DWORD wparam, HWND hWnd) const; CommandID HandleMIDIMessage(InputTargetContext context, uint32 message); Modified: trunk/OpenMPT/mptrack/view_com.cpp ============================================================================== --- trunk/OpenMPT/mptrack/view_com.cpp Wed Apr 3 20:24:00 2024 (r20489) +++ trunk/OpenMPT/mptrack/view_com.cpp Wed Apr 3 20:27:21 2024 (r20490) @@ -272,7 +272,7 @@ } else if(pMsg->message == WM_CHAR) { // Avoid Windows warning sound when holding note key - if(!CMainFrame::GetInputHandler()->IsBypassed() && CInputHandler::GetKeyEventType(HIWORD(pMsg->lParam)) == kKeyEventRepeat) + if(!CMainFrame::GetInputHandler()->IsBypassed() && CInputHandler::GetKeyEventType(*pMsg) == kKeyEventRepeat) return TRUE; } } |