System-wide mouse hook?

This is a discussion on System-wide mouse hook? within the basic.visual forums in Programming Languages category; I'm trying to write an application that would need to use a system- wide mouse hook. I know that it is not possible to write the required DLL in VB6, but I was hoping that someone might know of a free DLL that would work. I've been examining the Mabry MSGHOOK DLL, but it looks like it will only hook mouse events for one particular window, not the entire system. Does anyone have any good experience with a DLL to hook system mouse events in VB6? Brian...

Go Back   Application Development Forum > Programming Languages > basic.visual

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-24-2008, 01:35 PM
Brian
Guest
 
Default System-wide mouse hook?

I'm trying to write an application that would need to use a system-
wide mouse hook. I know that it is not possible to write the required
DLL in VB6, but I was hoping that someone might know of a free DLL
that would work.

I've been examining the Mabry MSGHOOK DLL, but it looks like it will
only hook mouse events for one particular window, not the entire
system.

Does anyone have any good experience with a DLL to hook system mouse
events in VB6?


Brian
Reply With Quote
  #2  
Old 08-24-2008, 02:57 PM
Mike Williams
Guest
 
Default Re: System-wide mouse hook?

On 24 Aug, 18:35, Brian <Brian.Aberna...@gmail.com> wrote:

> I'm trying to write an application that would
> need to use a system-wide mouse hook. *I know
> that it is not possible to write the required
> DLL in VB6, but I was hoping that someone might
> know of a free DLL that would work.


You don't need a DLL. Straight VB6 code will work fine. For example
the following code will insert a system wide mouse hook and, in this
specific example, will disable the right mouse button system wide
whilst your VB code is running (this is just a simple example and you
can of course do other things instead and you can control its
operation in various ways). As is always the case with standard VB6
subclassing code of this type, you should not close down the app in
the IDE other than by using the normal close button on your running
Form. In your compiled exe of course you don't need to worry about
this. Start a new VB project and add a standard Code module. Paste in
the following blocks of code, one into the Form and the other into the
module:

Mike

' *** START OF FORM CODE ***
Option Explicit
Private mouseHook As Long

Private Sub Form_Load()
mouseHook = SetWindowsHookEx(WH_MOUSE_LL, _
AddressOf MouseProc, App.hInstance, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
If mouseHook <> 0 Then
UnhookWindowsHookEx mouseHook
End If
End Sub
' *** END OF FORM CODE ***
'
' *** START OF MODULE CODE ***
Option Explicit
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
Public Const WH_MOUSE_LL As Long = 14
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" (Destination As Any, _
Source As Any, ByVal Length As Long)
Private Const HC_ACTION = 0
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_RBUTTONDBLCLK As Long = &H206
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Const WM_MBUTTONDOWN As Long = &H207
Private Const WM_MBUTTONUP As Long = &H208
Private Const WM_SCROLL As Long = &H20A
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type MOUSELLHOOKSTRUCT
point As POINTAPI
data As Long
flags As Long
time As Long
extra As Long
End Type
Private mousedata As MOUSELLHOOKSTRUCT

Public Function MouseProc(ByVal nCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim eatMouse As Boolean
If (nCode = HC_ACTION) Then
' Mouse data not used in this example, but useful
CopyMemory mousedata, ByVal lParam, Len(mousedata)
'
If wParam = WM_RBUTTONDOWN Or wParam = WM_RBUTTONUP Then
eatMouse = True
End If
End If
If eatMouse Then
MouseProc = -1
Else
MouseProc = CallNextHookEx _
(0, nCode, wParam, ByVal lParam)
End If
End Function
' *** END OF MODULE CODE ***


Reply With Quote
  #3  
Old 08-24-2008, 03:25 PM
Brian
Guest
 
Default Re: System-wide mouse hook?

Mike:

I wish I had gone back and re-read my original message. I guess I've
been Googling too long today. What I'm REALLY looking for is a way to
catch a system wide PASTE event. Since this could be either from the
mouse or a Ctrl-V, the mouse event really isn't what I'm looking for.
My sincere apologies.

Brian
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:56 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.