Get WHEEL_DELTA from wParam to WM_MOUSEHWHEEL msg in C #

I am using global interceptors from user32.dll with dllimport in C #. The keyboard works fine, but problems with the mouse wheel are a problem. This is my mouse event callback:

        private IntPtr MouseInputCallback(
            int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0) return CallNextHookEx(mouseHookId, nCode, wParam, lParam);

            int eventType = wParam.ToInt32();
            if (eventType == WM_MOUSEHWHEEL)
            {
                int wheelMovement = GetWheelDeltaWParam(eventType);
            }

            return CallNextHookEx(mouseHookId, nCode, wParam, lParam);
        }

Everything goes well until I need to get a WHEEL_DELTA value that shows how and how much the wheel was scrolled. Since there is no GET_WHEEL_DELTA_WPARAM macro in C # , I use this code, which should do the job:

private static int GetWheelDeltaWParam (int wparam) {return (int) (wparam β†’ 16); }

But the output is always 0, which makes no sense.

EDIT - result:

        MSLLHOOKSTRUCT mouseData = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
        int wheelMovement = GetWheelDeltaWParam(mouseData.mouseData);

        [StructLayout(LayoutKind.Sequential)]
        private struct MSLLHOOKSTRUCT
        {
            public Point pt;
            public int mouseData;
            public int flags;
            public int time;
            public long dwExtraInfo;
        }
+5
source share
2 answers

, GET_WHEEL_DELTA_WPARAM wParam WindowProc, LowLevelMouseProc. ,

wParam [in]

: WPARAM

. : WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN WM_RBUTTONUP.

wParam WM_MOUSEWHEEL; delta,

lParam [in]

: LPARAM

MSLLHOOKSTRUCT.

,

mouseData​​p >

: DWORD

WM_MOUSEWHEEL, . . , , ; , , . WHEEL_DELTA, 120.

.

, # P/Invoke , :)

+4

WM_MOUSE**H**WHEEL, ( ),

, WM_MOUSEWHEE L.

        if (eventType == WM_MOUSE**H**WHEEL)
        {
            int wheelMovement = GetWheelDeltaWParam(eventType);
        }

, ? , WM_MOUSEWHEEL , .

0
source

All Articles