diff --git a/plugins/LilyPad/LilyPad.cpp b/plugins/LilyPad/LilyPad.cpp index 40e7065492..58725ccb41 100644 --- a/plugins/LilyPad/LilyPad.cpp +++ b/plugins/LilyPad/LilyPad.cpp @@ -868,6 +868,16 @@ ExtraWndProcResult TitleHackWndProc(HWND hWndTop, UINT uMsg, WPARAM wParam, LPAR return CONTINUE_BLISSFULLY; } +// Useful sequence before changing into active/inactive state. +// Handles hooking/unhooking of mouse and KB and also mouse cursor visibility. +// towardsActive==true indicates we're gaining activity (on focus etc), false is for losing activity (on close, kill focus, etc). +void PrepareActivityState(bool towardsActive) { + if (!towardsActive) + ReleaseModifierKeys(); + activeWindow = towardsActive; + UpdateEnabledDevices(); +} + // responsible for monitoring device addition/removal, focus changes, and viewport closures. ExtraWndProcResult StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) { switch (uMsg) { @@ -887,11 +897,8 @@ ExtraWndProcResult StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa case WM_ACTIVATE: // Release any buttons PCSX2 may think are down when // losing/gaining focus. - if (!wParam) { - ReleaseModifierKeys(); - } - activeWindow = (LOWORD(wParam) != WA_INACTIVE); - UpdateEnabledDevices(); + // Note - I never managed to see this case entered, but SET/KILLFOCUS are entered. - avih 2014-04-16 + PrepareActivityState(LOWORD(wParam) != WA_INACTIVE); break; case WM_CLOSE: if (config.closeHacks & 1) { @@ -906,6 +913,12 @@ ExtraWndProcResult StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa case WM_DESTROY: QueueKeyEvent(VK_ESCAPE, KEYPRESS); break; + case WM_KILLFOCUS: + PrepareActivityState(false); + break; + case WM_SETFOCUS: + PrepareActivityState(true); + break; default: break; } @@ -1386,6 +1399,19 @@ keyEvent* CALLBACK PADkeyEvent() { static char altDown = 0; static keyEvent ev; if (!GetQueuedKeyEvent(&ev)) return 0; + + if (miceEnabled && (ev.key == VK_ESCAPE || (int)ev.key == -2) && ev.evt == KEYPRESS) { + // Disable mouse/KB hooks on escape (before going into paused mode). + // This is a hack, since PADclose (which is called on pause) should enevtually also deactivate the + // mouse/kb capture. In practice, WindowsMessagingMouse::Deactivate is called from PADclose, but doesn't + // manage to release the mouse, maybe due to the thread from which it's called or some + // state or somehow being too late. + // This explicitly triggers inactivity (releasing mouse/kb hooks) before PCSX2 starts to close the plugins. + // Regardless, the mouse/kb hooks will get re-enabled on resume if required without need for further hacks. + + PrepareActivityState(false); + } + if ((ev.key == VK_ESCAPE || (int)ev.key == -2) && ev.evt == KEYPRESS && config.escapeFullscreenHack) { static int t; if ((int)ev.key != -2 && IsWindowMaximized(hWndTop)) {