Skip to content
Permalink
Browse files

Merge pull request #12110 from LunaMoo/FixMouseScroll

Fix mouse scroll for key mapping
  • Loading branch information...
hrydgard committed Jun 18, 2019
2 parents 40d2d06 + b53e80c commit 53e8263371c2c48795c48666a3d5d6c3ca4e8d58
Showing with 44 additions and 21 deletions.
  1. +44 −21 Windows/MainWindow.cpp
@@ -103,8 +103,10 @@ extern ScreenManager *screenManager;

#define TIMER_CURSORUPDATE 1
#define TIMER_CURSORMOVEUPDATE 2
#define TIMER_WHEELRELEASE 3
#define CURSORUPDATE_INTERVAL_MS 1000
#define CURSORUPDATE_MOVE_TIMESPAN_MS 500
#define WHEELRELEASE_DELAY_MS 16

namespace MainWindow
{
@@ -130,6 +132,7 @@ namespace MainWindow
// gross hack
bool noFocusPause = false; // TOGGLE_PAUSE state to override pause on lost focus
bool trapMouse = true; // Handles some special cases(alt+tab, win menu) when game is running and mouse is confined
bool mouseScrollUsed = false;

#define MAX_LOADSTRING 100
const TCHAR *szWindowClass = TEXT("PPSSPPWnd");
@@ -256,6 +259,20 @@ namespace MainWindow
}
}

void RelaseMouseWheel() {
if (mouseScrollUsed) {
// For simplicity release both wheel events
KeyInput key;
key.deviceId = DEVICE_ID_MOUSE;
key.flags = KEY_UP;
key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
NativeKey(key);
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
NativeKey(key);
mouseScrollUsed = false;
}
}

static void HandleSizeChange(int newSizingType) {
SavePosition();
Core_NotifyWindowHidden(false);
@@ -657,6 +674,27 @@ namespace MainWindow
}
break;

case WM_MOUSEWHEEL:
{
int wheelDelta = (short)(wParam >> 16);
KeyInput key;
key.deviceId = DEVICE_ID_MOUSE;

if (wheelDelta < 0) {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
wheelDelta = -wheelDelta;
} else {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
}
// There's no separate keyup event for mousewheel events,
// so we set mouseScrollUsed here and always release if it's true.
key.flags = KEY_DOWN | KEY_HASWHEELDELTA | (wheelDelta << 16);
mouseScrollUsed = true;
SetTimer(hwndMain, TIMER_WHEELRELEASE, WHEELRELEASE_DELAY_MS, 0);
NativeKey(key);
}
break;

case WM_TOUCH:
{
touchHandler.handleTouchEvent(hWnd, message, wParam, lParam);
@@ -769,7 +807,7 @@ namespace MainWindow
}
break;

case WM_TIMER:
case WM_TIMER:
// Hack: Take the opportunity to also show/hide the mouse cursor in fullscreen mode.
switch (wParam) {
case TIMER_CURSORUPDATE:
@@ -780,26 +818,10 @@ namespace MainWindow
hideCursor = true;
KillTimer(hWnd, TIMER_CURSORMOVEUPDATE);
return 0;
}
break;

// For some reason, need to catch this here rather than in DisplayProc.
case WM_MOUSEWHEEL:
{
int wheelDelta = (short)(wParam >> 16);
KeyInput key;
key.deviceId = DEVICE_ID_MOUSE;

if (wheelDelta < 0) {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
wheelDelta = -wheelDelta;
} else {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
}
// There's no separate keyup event for mousewheel events, let's pass them both together.
// This also means it really won't work great for key mapping :( Need to build a 1 frame delay or something.
key.flags = KEY_DOWN | KEY_UP | KEY_HASWHEELDELTA | (wheelDelta << 16);
NativeKey(key);
// Hack: need to release wheel event without waiting for another wheel event.
case TIMER_WHEELRELEASE:
RelaseMouseWheel();
return 0;
}
break;

@@ -888,6 +910,7 @@ namespace MainWindow
case WM_DESTROY:
KillTimer(hWnd, TIMER_CURSORUPDATE);
KillTimer(hWnd, TIMER_CURSORMOVEUPDATE);
KillTimer(hWnd, TIMER_WHEELRELEASE);
PostQuitMessage(0);
break;

0 comments on commit 53e8263

Please sign in to comment.
You can’t perform that action at this time.