PC Review


Reply
Thread Tools Rate Thread

Capturing mouse events (Mouse up and down on the desktop)

 
 
Ahmed
Guest
Posts: n/a
 
      6th Jun 2006
Hi,

I am trying to capture the mouse events when the user clicks on the
desktop not the winform. I looked at the mouse_event function but MSDN
documentation says that it is suppressed in win NT/2000/XP. What I am
trying to do is to get print screen for a section on the desktop every
number of seconds. And I want the user to be able to select that
region.

Any help will be appreciated.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      6th Jun 2006
if you want to get a mouseclick event, just hook the mouse so it will tell
you whenever the mouse button is clicked
--
-iwdu15
 
Reply With Quote
 
Ahmed
Guest
Posts: n/a
 
      7th Jun 2006
That's true when you click on the form. But if you click outside the
form the even doesn't capture mouse events.


iwdu15 wrote:
> if you want to get a mouseclick event, just hook the mouse so it will tell
> you whenever the mouse button is clicked
> --
> -iwdu15


 
Reply With Quote
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      7th Jun 2006
sorry for not being clear, i meant put a mouse hook on the formload event.
then you can receive every mouse click....ex:



Private Const HC_ACTION As Integer = 0
Private Const WH_MOUSE_LL As Integer = 14
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_MOUSEWHEEL As Integer = &H20A

Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" ( _
ByVal idHook As Integer, _
ByVal lpfn As LowLevelMouseProcDelegate, _
ByVal hmod As Integer, _
ByVal dwThreadId As Integer) As Integer

Private Declare Function CallNextHookEx Lib "user32" ( _
ByVal hHook As Integer, _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As MSLLHOOKSTRUCT) As Integer

Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Integer) As Integer

Private Function LowLevelMouseProc( _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As MSLLHOOKSTRUCT) As Integer

If (nCode = HC_ACTION) Then

If wParam = WM_LBUTTONDOWN Then

''do something on left mouse click

End If

Return CallNextHookEx(hhkLowLevelMouse, _
nCode, wParam, lParam)

End If

End Function

Private Delegate Function LowLevelMouseProcDelegate( _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As MSLLHOOKSTRUCT) As Integer


''set mouse hook
Public Sub DisableMouse()

'Set Mouse Hook
hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, _
AddressOf LowLevelMouseProc, _

Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, _
0)

End Sub


''release hook
Public Sub EnableMouse()

'Release Mouse Hook
UnhookWindowsHookEx(hhkLowLevelMouse)

End Sub


hope this helps

--
-iwdu15
 
Reply With Quote
 
Ahmed
Guest
Posts: n/a
 
      7th Jun 2006
Thanks alot. I think that almost did that trick except it is generating
an exception when reaching line:

Return CallNextHookEx(hhkLowLevelMouse, _
nCode, wParam, lParam)


That exception was about Stack. I will post the full exception message
when I get home.

Thanks again.


iwdu15 wrote:
> sorry for not being clear, i meant put a mouse hook on the formload event.
> then you can receive every mouse click....ex:
>
>
>
> Private Const HC_ACTION As Integer = 0
> Private Const WH_MOUSE_LL As Integer = 14
> Private Const WM_LBUTTONDOWN As Integer = &H201
> Private Const WM_MOUSEWHEEL As Integer = &H20A
>
> Private Declare Function SetWindowsHookEx Lib "user32" _
> Alias "SetWindowsHookExA" ( _
> ByVal idHook As Integer, _
> ByVal lpfn As LowLevelMouseProcDelegate, _
> ByVal hmod As Integer, _
> ByVal dwThreadId As Integer) As Integer
>
> Private Declare Function CallNextHookEx Lib "user32" ( _
> ByVal hHook As Integer, _
> ByVal nCode As Integer, _
> ByVal wParam As Integer, _
> ByVal lParam As MSLLHOOKSTRUCT) As Integer
>
> Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
> ByVal hHook As Integer) As Integer
>
> Private Function LowLevelMouseProc( _
> ByVal nCode As Integer, _
> ByVal wParam As Integer, _
> ByVal lParam As MSLLHOOKSTRUCT) As Integer
>
> If (nCode = HC_ACTION) Then
>
> If wParam = WM_LBUTTONDOWN Then
>
> ''do something on left mouse click
>
> End If
>
> Return CallNextHookEx(hhkLowLevelMouse, _
> nCode, wParam, lParam)
>
> End If
>
> End Function
>
> Private Delegate Function LowLevelMouseProcDelegate( _
> ByVal nCode As Integer, _
> ByVal wParam As Integer, _
> ByVal lParam As MSLLHOOKSTRUCT) As Integer
>
>
> ''set mouse hook
> Public Sub DisableMouse()
>
> 'Set Mouse Hook
> hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, _
> AddressOf LowLevelMouseProc, _
>
> Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, _
> 0)
>
> End Sub
>
>
> ''release hook
> Public Sub EnableMouse()
>
> 'Release Mouse Hook
> UnhookWindowsHookEx(hhkLowLevelMouse)
>
> End Sub
>
>
> hope this helps
>
> --
> -iwdu15


 
Reply With Quote
 
Ahmed
Guest
Posts: n/a
 
      7th Jun 2006
I think I know what the problem is. I just searched the news group and
I found the following thread:

http://groups.google.ca/group/micros...bcdefa8cc811ca

It suggests replaceing the byval to byref for the fourth parameter in
the method. I will try it at home and I will let everybody know.

Thanks again

Ahmed wrote:
> Thanks alot. I think that almost did that trick except it is generating
> an exception when reaching line:
>
> Return CallNextHookEx(hhkLowLevelMouse, _
> nCode, wParam, lParam)
>
>
> That exception was about Stack. I will post the full exception message
> when I get home.
>
> Thanks again.
>
>
> iwdu15 wrote:
> > sorry for not being clear, i meant put a mouse hook on the formload event.
> > then you can receive every mouse click....ex:
> >
> >
> >
> > Private Const HC_ACTION As Integer = 0
> > Private Const WH_MOUSE_LL As Integer = 14
> > Private Const WM_LBUTTONDOWN As Integer = &H201
> > Private Const WM_MOUSEWHEEL As Integer = &H20A
> >
> > Private Declare Function SetWindowsHookEx Lib "user32" _
> > Alias "SetWindowsHookExA" ( _
> > ByVal idHook As Integer, _
> > ByVal lpfn As LowLevelMouseProcDelegate, _
> > ByVal hmod As Integer, _
> > ByVal dwThreadId As Integer) As Integer
> >
> > Private Declare Function CallNextHookEx Lib "user32" ( _
> > ByVal hHook As Integer, _
> > ByVal nCode As Integer, _
> > ByVal wParam As Integer, _
> > ByVal lParam As MSLLHOOKSTRUCT) As Integer
> >
> > Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
> > ByVal hHook As Integer) As Integer
> >
> > Private Function LowLevelMouseProc( _
> > ByVal nCode As Integer, _
> > ByVal wParam As Integer, _
> > ByVal lParam As MSLLHOOKSTRUCT) As Integer
> >
> > If (nCode = HC_ACTION) Then
> >
> > If wParam = WM_LBUTTONDOWN Then
> >
> > ''do something on left mouse click
> >
> > End If
> >
> > Return CallNextHookEx(hhkLowLevelMouse, _
> > nCode, wParam, lParam)
> >
> > End If
> >
> > End Function
> >
> > Private Delegate Function LowLevelMouseProcDelegate( _
> > ByVal nCode As Integer, _
> > ByVal wParam As Integer, _
> > ByVal lParam As MSLLHOOKSTRUCT) As Integer
> >
> >
> > ''set mouse hook
> > Public Sub DisableMouse()
> >
> > 'Set Mouse Hook
> > hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, _
> > AddressOf LowLevelMouseProc, _
> >
> > Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, _
> > 0)
> >
> > End Sub
> >
> >
> > ''release hook
> > Public Sub EnableMouse()
> >
> > 'Release Mouse Hook
> > UnhookWindowsHookEx(hhkLowLevelMouse)
> >
> > End Sub
> >
> >
> > hope this helps
> >
> > --
> > -iwdu15


 
Reply With Quote
 
Ahmed
Guest
Posts: n/a
 
      8th Jun 2006
Thanks, its working fine.
Ahmed wrote:
> I think I know what the problem is. I just searched the news group and
> I found the following thread:
>
> http://groups.google.ca/group/micros...bcdefa8cc811ca
>
> It suggests replaceing the byval to byref for the fourth parameter in
> the method. I will try it at home and I will let everybody know.
>
> Thanks again
>
> Ahmed wrote:
> > Thanks alot. I think that almost did that trick except it is generating
> > an exception when reaching line:
> >
> > Return CallNextHookEx(hhkLowLevelMouse, _
> > nCode, wParam, lParam)
> >
> >
> > That exception was about Stack. I will post the full exception message
> > when I get home.
> >
> > Thanks again.
> >
> >
> > iwdu15 wrote:
> > > sorry for not being clear, i meant put a mouse hook on the formload event.
> > > then you can receive every mouse click....ex:
> > >
> > >
> > >
> > > Private Const HC_ACTION As Integer = 0
> > > Private Const WH_MOUSE_LL As Integer = 14
> > > Private Const WM_LBUTTONDOWN As Integer = &H201
> > > Private Const WM_MOUSEWHEEL As Integer = &H20A
> > >
> > > Private Declare Function SetWindowsHookEx Lib "user32" _
> > > Alias "SetWindowsHookExA" ( _
> > > ByVal idHook As Integer, _
> > > ByVal lpfn As LowLevelMouseProcDelegate, _
> > > ByVal hmod As Integer, _
> > > ByVal dwThreadId As Integer) As Integer
> > >
> > > Private Declare Function CallNextHookEx Lib "user32" ( _
> > > ByVal hHook As Integer, _
> > > ByVal nCode As Integer, _
> > > ByVal wParam As Integer, _
> > > ByVal lParam As MSLLHOOKSTRUCT) As Integer
> > >
> > > Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
> > > ByVal hHook As Integer) As Integer
> > >
> > > Private Function LowLevelMouseProc( _
> > > ByVal nCode As Integer, _
> > > ByVal wParam As Integer, _
> > > ByVal lParam As MSLLHOOKSTRUCT) As Integer
> > >
> > > If (nCode = HC_ACTION) Then
> > >
> > > If wParam = WM_LBUTTONDOWN Then
> > >
> > > ''do something on left mouse click
> > >
> > > End If
> > >
> > > Return CallNextHookEx(hhkLowLevelMouse, _
> > > nCode, wParam, lParam)
> > >
> > > End If
> > >
> > > End Function
> > >
> > > Private Delegate Function LowLevelMouseProcDelegate( _
> > > ByVal nCode As Integer, _
> > > ByVal wParam As Integer, _
> > > ByVal lParam As MSLLHOOKSTRUCT) As Integer
> > >
> > >
> > > ''set mouse hook
> > > Public Sub DisableMouse()
> > >
> > > 'Set Mouse Hook
> > > hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, _
> > > AddressOf LowLevelMouseProc, _
> > >
> > > Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, _
> > > 0)
> > >
> > > End Sub
> > >
> > >
> > > ''release hook
> > > Public Sub EnableMouse()
> > >
> > > 'Release Mouse Hook
> > > UnhookWindowsHookEx(hhkLowLevelMouse)
> > >
> > > End Sub
> > >
> > >
> > > hope this helps
> > >
> > > --
> > > -iwdu15


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing Mouse events oiutside a control HaySeed Microsoft Dot NET Framework Forms 4 3rd Dec 2008 06:25 AM
Capturing mouse events (Mouse up and down on the desktop) Ahmed Microsoft Dot NET Framework Forms 0 6th Jun 2006 06:54 PM
Capturing mouse, key events Schemer Microsoft Dot NET Framework Forms 22 18th Aug 2005 02:50 AM
Capturing mouse wheel events Evgeny Zoldin Microsoft C# .NET 2 23rd Nov 2003 10:39 PM
Capturing mouse wheel events Evgeny Zoldin Microsoft Dot NET 2 23rd Nov 2003 10:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:08 PM.