You need to use the SetWindowsHookEx function and specify the hook type as *WH_MOUSE_LL* (14). Have the following declaration.
Public Structure Point
Public X As Integer
Public Y As Integer
End Structure
Public Structure Msllhookstruct
Public Location As Point
Public MouseData As Integer
Public Flags As Integer
Public Time As Integer
Public ExtraInfo As Integer
End Structure
Private Delegate Function HookProc(nCode As Integer, wParam As Integer, ByRef lParam As Msllhookstruct) As Integer
<DllImport("user32.dll", SetLastError:=True)> _
Private Function SetWindowsHookEx(ByVal hookType As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As Msllhookstruct) As IntPtr
End Function
Private Hook As IntPtr
In your initialising routine, use it as follow
Hook = SetWindowsHookEx(14, AddressOf Proc, Process.GetCurrentProcess().MainModule.BaseAddress.ToInt32(), 0)
Where Proc
is a function callback like so:
Private Function Proc(nCode As Integer, wParam As Integer, ByRef lParam As Msllhookstruct) As IntPtr
If wParam = 522 Then
Dim Delta = CShort(lParam.MouseData >> 16)
If Delta > 0 Then
' Up
ElseIf Delta < 0 Then
' Down
End If
End If
Return CallNextHookEx(Hook, nCode, wParam, lParam)
End Function