I'm using global hooks from user32.dll with dllimport in C#. Keyboard one works fine, but the mouse wheel events 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 fine until I have to retrieve the WHEEL_DELTA value that shows which way and how much the wheel was scrolled. Since C# lacks the GET_WHEEL_DELTA_WPARAM macro, I'm using this code that should do the job:
private static int GetWheelDeltaWParam(int wparam) { return (int)(wparam >> 16); }
But the output is always 0, which doesn't make any 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;
}
wParam
for equality with the message id, but then want the same value's top 16 bits to vary? – Extraditable