diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index fd077c4..08fbb36 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -4732,11 +4732,19 @@ namespace olc // Windows Event Handler - this is statically connected to the windows event system static LRESULT CALLBACK olc_WindowEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + static BOOL bTrackMouseEventSet = FALSE; + switch (uMsg) { - switch (uMsg) - { - case WM_MOUSEMOVE: + case WM_MOUSEMOVE: + { + if (!bTrackMouseEventSet) { + bTrackMouseEventSet = TRUE; + TRACKMOUSEEVENT tme{ sizeof(TRACKMOUSEEVENT), TME_LEAVE, hWnd }; TrackMouseEvent(&tme); + ptrPGE->olc_UpdateMouseState(0, wParam == MK_LBUTTON); + ptrPGE->olc_UpdateMouseState(1, wParam == MK_RBUTTON); + ptrPGE->olc_UpdateMouseState(2, wParam == MK_MBUTTON); + } // Thanks @ForAbby (Discord) uint16_t x = lParam & 0xFFFF; uint16_t y = (lParam >> 16) & 0xFFFF; int16_t ix = *(int16_t*)&x; int16_t iy = *(int16_t*)&y; @@ -4745,7 +4753,7 @@ namespace olc } case WM_SIZE: ptrPGE->olc_UpdateWindowSize(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); return 0; case WM_MOUSEWHEEL: ptrPGE->olc_UpdateMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); return 0; - case WM_MOUSELEAVE: ptrPGE->olc_UpdateMouseFocus(false); return 0; + case WM_MOUSELEAVE: bTrackMouseEventSet = FALSE; ptrPGE->olc_UpdateMouseFocus(false); return 0; case WM_SETFOCUS: ptrPGE->olc_UpdateKeyFocus(true); return 0; case WM_KILLFOCUS: ptrPGE->olc_UpdateKeyFocus(false); return 0; case WM_KEYDOWN: ptrPGE->olc_UpdateKeyState(mapKeys[wParam], true); return 0;