diff --git a/mptrack/AbstractVstEditor.cpp b/mptrack/AbstractVstEditor.cpp index 72cad3b505..2196cc1042 100644 --- a/mptrack/AbstractVstEditor.cpp +++ b/mptrack/AbstractVstEditor.cpp @@ -450,7 +450,7 @@ BOOL CAbstractVstEditor::PreTranslateMessage(MSG *msg) } -bool CAbstractVstEditor::HandleKeyMessage(MSG &msg) +bool CAbstractVstEditor::HandleKeyMessage(MSG &msg, bool handleGlobal) { if(m_VstPlugin.m_passKeypressesToPlug) return false; @@ -467,6 +467,9 @@ bool CAbstractVstEditor::HandleKeyMessage(MSG &msg) if(ih->KeyEvent(kCtxVSTGUI, event, this) != kcNull) return true; + if(handleGlobal && HandleGlobalKeyMessage(msg)) + return true; + // Don't forward key repeats if plug does not listen for keypresses // (avoids system beeps on note hold) if(event.keyEventType == kKeyEventRepeat) diff --git a/mptrack/AbstractVstEditor.h b/mptrack/AbstractVstEditor.h index 15170689c1..d1ebcc7551 100644 --- a/mptrack/AbstractVstEditor.h +++ b/mptrack/AbstractVstEditor.h @@ -112,7 +112,7 @@ class CAbstractVstEditor : public DialogBase protected: BOOL PreTranslateMessage(MSG *msg) override; - bool HandleKeyMessage(MSG &msg); + bool HandleKeyMessage(MSG &msg, bool handleGlobal = false); void UpdatePresetMenu(bool force = false); void GeneratePresetMenu(int32 offset, CMenu &parent); void UpdateInputMenu(); diff --git a/mptrack/DialogBase.cpp b/mptrack/DialogBase.cpp index 17b21cc5f8..d88f7bbdad 100644 --- a/mptrack/DialogBase.cpp +++ b/mptrack/DialogBase.cpp @@ -16,23 +16,33 @@ OPENMPT_NAMESPACE_BEGIN BOOL DialogBase::PreTranslateMessage(MSG *pMsg) +{ + if(pMsg && HandleGlobalKeyMessage(*pMsg)) + return TRUE; + + return CDialog::PreTranslateMessage(pMsg); +} + + +bool DialogBase::HandleGlobalKeyMessage(const MSG &msg) const { // We handle keypresses before Windows has a chance to handle them (for alt etc..) - if(pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP || pMsg->message == WM_SYSKEYDOWN) + if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP || msg.message == WM_SYSKEYDOWN) { if(CInputHandler *ih = CMainFrame::GetInputHandler()) { - const auto event = ih->Translate(*pMsg); + const auto event = ih->Translate(msg); if(ih->KeyEvent(kCtxAllContexts, event) != kcNull) { // Special case: ESC is typically bound to stopping playback, but we also want to allow ESC to close dialogs - if(pMsg->message != WM_KEYDOWN || pMsg->wParam != VK_ESCAPE) - return TRUE; // Mapped to a command, no need to pass message on. + if(msg.message != WM_KEYDOWN || msg.wParam != VK_ESCAPE) + return true; // Mapped to a command, no need to pass message on. } } } - return CDialog::PreTranslateMessage(pMsg); + return false; } + OPENMPT_NAMESPACE_END diff --git a/mptrack/DialogBase.h b/mptrack/DialogBase.h index 3ac7de6308..5be53cdacf 100644 --- a/mptrack/DialogBase.h +++ b/mptrack/DialogBase.h @@ -21,6 +21,9 @@ class DialogBase : public CDialog using CDialog::CDialog; BOOL PreTranslateMessage(MSG *pMsg) override; + +protected: + bool HandleGlobalKeyMessage(const MSG &msg) const; }; OPENMPT_NAMESPACE_END diff --git a/mptrack/VSTEditor.h b/mptrack/VSTEditor.h index 81d29cafc4..51bb9f61e1 100644 --- a/mptrack/VSTEditor.h +++ b/mptrack/VSTEditor.h @@ -50,7 +50,7 @@ class COwnerVstEditor : public CAbstractVstEditor LRESULT HandlePreTranslateMessage(UINT message, WPARAM wParam, LPARAM lParam) { MSG msg = {m_plugWindow, message, wParam, lParam, 0, {}}; - return PreTranslateMessage(&msg); + return HandleKeyMessage(msg, true); } DECLARE_MESSAGE_MAP()