From 6300a47c1545580162ac7bd724636d4ec55ba649 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Sun, 3 Jan 2016 20:53:18 +0200 Subject: [PATCH] GS window: improve keys/commands handling when paused Only relevant if the GS window is set to NOT hide when paused. At this case there were two issues on Windows: - Commands were invoked twice. - Non-special-keys (e.g. plain 'q') were not handled at all. Not terribly important now, but it prepares for the next commit. Also rename a function to have a more meaningful name. --- pcsx2/gui/FrameForGS.cpp | 25 ++++++++++++++++++++++--- pcsx2/gui/GSFrame.h | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index efcd22722f..68df27a745 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -101,8 +101,8 @@ GSPanel::GSPanel( wxWindow* parent ) Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler (GSPanel::OnCloseWindow)); Connect(wxEVT_SIZE, wxSizeEventHandler (GSPanel::OnResize)); - Connect(wxEVT_KEY_UP, wxKeyEventHandler (GSPanel::OnKeyDown)); - Connect(wxEVT_KEY_DOWN, wxKeyEventHandler (GSPanel::OnKeyDown)); + Connect(wxEVT_KEY_UP, wxKeyEventHandler (GSPanel::OnKeyDownOrUp)); + Connect(wxEVT_KEY_DOWN, wxKeyEventHandler (GSPanel::OnKeyDownOrUp)); Connect(wxEVT_SET_FOCUS, wxFocusEventHandler (GSPanel::OnFocus)); Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler (GSPanel::OnFocusLost)); @@ -263,7 +263,7 @@ void GSPanel::OnHideMouseTimeout( wxTimerEvent& evt ) m_CursorShown = false; } -void GSPanel::OnKeyDown( wxKeyEvent& evt ) +void GSPanel::OnKeyDownOrUp( wxKeyEvent& evt ) { // HACK: Legacy PAD plugins expect PCSX2 to ignore keyboard messages on the GS Window while @@ -288,6 +288,25 @@ void GSPanel::OnKeyDown( wxKeyEvent& evt ) } #endif +#ifdef __WXMSW__ + // Not sure what happens on Linux, but on windows this method is called only when emulation + // is paused and the GS window is not hidden (and therefore the event doesn't arrive from + // the pad plugin and doesn't go through Pcsx2App::PadKeyDispatch). On such case (paused). + // It needs to handle two issues: + // 1. It's called both for key down and key up (linux apparently needs it this way) - but we + // don't want to execute the command twice (normally commands execute on key down only). + // 2. It has wx keycode which is upper case for ascii chars, but our command handlers expect + // lower case for non-special keys. + + // ignore key up events + if (evt.GetEventType() == wxEVT_KEY_UP) + return; + + // Make ascii keys lower case - this apparently works correctly also with modifiers (shift included) + if (evt.m_keyCode >= 'A' && evt.m_keyCode <= 'Z') + evt.m_keyCode += (int)'a' - 'A'; +#endif + if( (PADopen != NULL) && CoreThread.IsOpen() ) return; DirectKeyCommand( evt ); } diff --git a/pcsx2/gui/GSFrame.h b/pcsx2/gui/GSFrame.h index 808b92f032..bff1e4bd37 100644 --- a/pcsx2/gui/GSFrame.h +++ b/pcsx2/gui/GSFrame.h @@ -63,7 +63,7 @@ protected: void OnResize(wxSizeEvent& event); void OnMouseEvent( wxMouseEvent& evt ); void OnHideMouseTimeout( wxTimerEvent& evt ); - void OnKeyDown( wxKeyEvent& evt ); + void OnKeyDownOrUp( wxKeyEvent& evt ); void OnFocus( wxFocusEvent& evt ); void OnFocusLost( wxFocusEvent& evt ); void CoreThread_OnResumed();