Re: Hook for mouse right click



Thank you for you source
I've tried to find an answer before I post thisquestion here, but didn't get
a satisfactory result until now.

But thanks again and forgive me any trouble

"DanS" <t.h.i.s.n.t.h.a.t@xxxxxxxxxxxxxxxxxxxxxx> escreveu na mensagem
news:Xns9759C938EA3FDidispcom@xxxxxxxxxxxxxxxxx
> "WebNewsReader" <none@xxxxxxxxxxxx> wrote in
> news:eiJmCRCJGHA.1288@xxxxxxxxxxxxxxxxxxxx:
>
>> I would like to know how it's possible to hook the mouse right click
>> using windows API.
>> Thanks in advance
>>
>>
>
> And to MY knowledge, this is the third or 4th time I've posted this code
> to do EXACTLY what you want, a global kbd or mouse hook directly in your
> VB program w/o any DLL...for 2K or XP only.
>
> Create a new module, and name it something, paste in this code. You may
> need to fix the wrapping.
>
> Use start or stopMouseHook, or start or stopKeyboardhook, whatever your
> need.
>
> Don't forget to stop the hook before exiting your app.
>
> DanS
>
>
> ---Start Code-----------------------------------
> Option Explicit
>
> Public Const WH_KEYBOARD_LL = 13
> Private Const WH_MOUSE_LL As Long = 14
>
> Private Const HC_ACTION As Integer = 0
>
> Private Const WM_MOUSEMOVE As Integer = &H200
> Private Const WM_LBUTTONDOWN As Integer = &H201
> Private Const WM_LBUTTONUP As Integer = &H202
> Private Const WM_LBUTTONDBLCLK As Integer = &H203
> Private Const WM_RBUTTONDOWN As Integer = &H204
> Private Const WM_RBUTTONUP As Integer = &H205
> Private Const WM_RBUTTONDBLCLK As Integer = &H206
> Private Const WM_MBUTTONDOWN As Integer = &H207
> Private Const WM_MBUTTONUP As Integer = &H208
> Private Const WM_MBUTTONDBLCLK As Integer = &H209
> Private Const WM_MOUSEWHEEL As Integer = &H20A
>
>
>
> Private Type KBDLLHOOKSTRUCT
> vkCode As Long ' virtual key code
> scanCode As Long ' scan code
> flags As Long ' flags
> time As Long ' time stamp for this message
> dwExtraInfo As Long ' extra info from the driver or keybd_event
> End Type
>
> Private Type Point
> x As Long
> y As Long
> End Type
>
> Private Type MSLLHOOKSTRUCT
> pt As Point
> mouseData As Integer
> flags As Integer
> time As Integer
> dwExtraInfo As Integer
> End Type
>
> Public Declare Function SetWindowsHookEx Lib "user32" Alias
> "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod
> As Long, ByVal dwThreadId As Long) As Long
> Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As
> Long) As Long
>
> Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As
> Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
> Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
> (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
>
> Private kb_struct As KBDLLHOOKSTRUCT
> Private mouse_struct As MSLLHOOKSTRUCT
>
> Global kbd_Hook As Long
> Global mouse_Hook As Long
>
> Public Function startKeyboardHook() As Boolean
>
> kbd_Hook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardProc,
> App.hInstance, ByVal 0&)
> If kbd_Hook <> 0 Then
> startKeyboardHook = True
> End If
>
> End Function
>
> Public Sub stopKeyboardHook()
> UnhookWindowsHookEx kbd_Hook
> End Sub
> Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long,
> ByVal lParam As Long) As Long
> If nCode = HC_ACTION Then
> CopyMemory kb_struct, ByVal lParam, LenB(kb_struct)
> Debug.Print kb_struct.scanCode
> End If
> KeyboardProc = CallNextHookEx(kbd_Hook, nCode, wParam, lParam)
> End Function
>
> Public Function startMouseHook() As Boolean
> mouse_Hook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc,
> App.hInstance, ByVal 0&)
> If mouse_Hook <> 0 Then
> startMouseHook = True
> End If
> End Function
>
> Public Sub stopMouseHook()
> UnhookWindowsHookEx mouse_Hook
> End Sub
>
> Public Function MouseProc(ByVal nCode As Long, ByVal wParam As Long,
> ByVal lParam As Long) As Long
> If nCode = HC_ACTION Then
> CopyMemory mouse_struct, ByVal lParam, LenB(mouse_struct)
> Select Case wParam
> Case WM_MOUSEMOVE
>
> Case WM_LBUTTONDOWN
>
> Case WM_LBUTTONUP
>
> Case WM_LBUTTONDBLCLK
>
> Case WM_RBUTTONDOWN
>
> Case WM_RBUTTONUP
>
> Case WM_RBUTTONDBLCLK
>
> Case WM_MBUTTONDOWN
>
> Case WM_MBUTTONDBLCLK
>
> Case WM_MOUSEWHEEL
> End Select
> End If
> MouseProc = CallNextHookEx(mouse_Hook, nCode, wParam, lParam)
> End Function
>
> ---End of Code---------------------------------------------------


.