473,761 Members | 8,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mouse Hook in C#

I need to know where the cursor is (x,y) and when it moves even when it is
not over my form. I know i can get the current location with:
System.Windows. Forms.Cursor.Po sition.X
System.Windows. Forms.Cursor.Po sition.X
But that does not raise an event and using a timer would be to processor
intensive. In MFC you would write a mousehook to solve this problem but when
i run the C# MouseHook code for from MSDN
(http://support.microsoft.com/?kbid=318804) it only seems to return anything
when the mouse is over the form. I am guessing i am doing something wrong
with the MouseHook.
Thanks in advance,
~Logan
Nov 15 '05 #1
5 7096
Hi,

To achieve this you will have to install a system wide hook. As per the MSDN
documentation this is not possible using a managed assembly. You will have
to do this using C/C++ and then one option might be to expose an interface
that marshals the information back to the managed application.

Hope this helps

Chris Taylor

"Logan Mckinley" <lo***@globalwe b.net> wrote in message
news:eC******** ********@TK2MSF TNGP09.phx.gbl. ..
I need to know where the cursor is (x,y) and when it moves even when it is
not over my form. I know i can get the current location with:
System.Windows. Forms.Cursor.Po sition.X
System.Windows. Forms.Cursor.Po sition.X
But that does not raise an event and using a timer would be to processor
intensive. In MFC you would write a mousehook to solve this problem but when i run the C# MouseHook code for from MSDN
(http://support.microsoft.com/?kbid=318804) it only seems to return anything when the mouse is over the form. I am guessing i am doing something wrong
with the MouseHook.
Thanks in advance,
~Logan

Nov 15 '05 #2
I presume they plan on filling these huge gaps in the libraries?
"Chris Taylor" <ch************ *@hotmail.com> wrote in message
news:#P******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

To achieve this you will have to install a system wide hook. As per the MSDN documentation this is not possible using a managed assembly. You will have to do this using C/C++ and then one option might be to expose an interface
that marshals the information back to the managed application.

Hope this helps

Chris Taylor

"Logan Mckinley" <lo***@globalwe b.net> wrote in message
news:eC******** ********@TK2MSF TNGP09.phx.gbl. ..
I need to know where the cursor is (x,y) and when it moves even when it is not over my form. I know i can get the current location with:
System.Windows. Forms.Cursor.Po sition.X
System.Windows. Forms.Cursor.Po sition.X
But that does not raise an event and using a timer would be to processor
intensive. In MFC you would write a mousehook to solve this problem but

when
i run the C# MouseHook code for from MSDN
(http://support.microsoft.com/?kbid=318804) it only seems to return

anything
when the mouse is over the form. I am guessing i am doing something wrong with the MouseHook.
Thanks in advance,
~Logan


Nov 15 '05 #3
Not being a MS Insider I can only guess, but with time I am sure more and
more of the missing functiontionali ty will be addressed. However I think
that .NET is targeting application development and for a long time to come
we will be using C/C++ to write the more system level type code. While .NET
will provide a more secure environment for application level tasks.

Those are just my thoughts

Chris Taylor
"anonymouse " <an********@dis cussions.micros oft.com> wrote in message
news:O0******** ******@TK2MSFTN GP11.phx.gbl...
I presume they plan on filling these huge gaps in the libraries?
"Chris Taylor" <ch************ *@hotmail.com> wrote in message
news:#P******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

To achieve this you will have to install a system wide hook. As per the MSDN
documentation this is not possible using a managed assembly. You will

have
to do this using C/C++ and then one option might be to expose an interface
that marshals the information back to the managed application.

Hope this helps

Chris Taylor

"Logan Mckinley" <lo***@globalwe b.net> wrote in message
news:eC******** ********@TK2MSF TNGP09.phx.gbl. ..
I need to know where the cursor is (x,y) and when it moves even when it is not over my form. I know i can get the current location with:
System.Windows. Forms.Cursor.Po sition.X
System.Windows. Forms.Cursor.Po sition.X
But that does not raise an event and using a timer would be to
processor intensive. In MFC you would write a mousehook to solve this problem
but when
i run the C# MouseHook code for from MSDN
(http://support.microsoft.com/?kbid=318804) it only seems to return

anything
when the mouse is over the form. I am guessing i am doing something

wrong with the MouseHook.
Thanks in advance,
~Logan



Nov 15 '05 #4
So does the C# MouseHook per the MSDN article i posted catch mouse movements
across all of the elements of your form?
Thanks,
~Logan
"Chris Taylor" <ch************ *@hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

To achieve this you will have to install a system wide hook. As per the MSDN documentation this is not possible using a managed assembly. You will have to do this using C/C++ and then one option might be to expose an interface
that marshals the information back to the managed application.

Hope this helps

Chris Taylor

"Logan Mckinley" <lo***@globalwe b.net> wrote in message
news:eC******** ********@TK2MSF TNGP09.phx.gbl. ..
I need to know where the cursor is (x,y) and when it moves even when it is not over my form. I know i can get the current location with:
System.Windows. Forms.Cursor.Po sition.X
System.Windows. Forms.Cursor.Po sition.X
But that does not raise an event and using a timer would be to processor
intensive. In MFC you would write a mousehook to solve this problem but

when
i run the C# MouseHook code for from MSDN
(http://support.microsoft.com/?kbid=318804) it only seems to return

anything
when the mouse is over the form. I am guessing i am doing something wrong with the MouseHook.
Thanks in advance,
~Logan


Nov 15 '05 #5
Hi,

Yes, just to be certain I took an existing form with a multiline edit
control, three buttons a menu and a single line edit control plug the code
into the form and no matter where I moved with in the confines of the form
the hook function was called.

Chris Taylor

"Logan Mckinley" <lo***@globalwe b.net> wrote in message
news:eU******** ******@tk2msftn gp13.phx.gbl...
So does the C# MouseHook per the MSDN article i posted catch mouse movements across all of the elements of your form?
Thanks,
~Logan
"Chris Taylor" <ch************ *@hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

To achieve this you will have to install a system wide hook. As per the MSDN
documentation this is not possible using a managed assembly. You will

have
to do this using C/C++ and then one option might be to expose an interface
that marshals the information back to the managed application.

Hope this helps

Chris Taylor

"Logan Mckinley" <lo***@globalwe b.net> wrote in message
news:eC******** ********@TK2MSF TNGP09.phx.gbl. ..
I need to know where the cursor is (x,y) and when it moves even when it is not over my form. I know i can get the current location with:
System.Windows. Forms.Cursor.Po sition.X
System.Windows. Forms.Cursor.Po sition.X
But that does not raise an event and using a timer would be to
processor intensive. In MFC you would write a mousehook to solve this problem
but when
i run the C# MouseHook code for from MSDN
(http://support.microsoft.com/?kbid=318804) it only seems to return

anything
when the mouse is over the form. I am guessing i am doing something

wrong with the MouseHook.
Thanks in advance,
~Logan



Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12597
by: paul francis | last post by:
Hi Please help because I'm really stuck: I'm trying to write an application in C# which can be used to track the mouse pointer position on any window. I'm trying to use a Global mouse hook to do this but with limited success. According to the documentation (as I understand it) you can only do Global hooks in ..Net if the delegate procedure passed to SetWindowsHookEx is external.
9
5727
by: Will Pittenger | last post by:
If I were writing a C++ program, I would write a mouse hook. Does C# and ..NET 1.1 have anything equivalent. If not, I suppose I will need to use the Win32 API. ---------- Will Pittenger E-Mail: mailto:will.pittenger@verizon.net All mail filtered by Qurb (www.qurb.com)
3
8427
by: june | last post by:
Hi, I am coding for an application with dialog window. I need intercept mouse input. I need catch raw input, pretty much everything for WM_INPUT: such as Left/Middle/Right button down/up, srcoll/wheel, pull and drag, device source. I checked SetWindowsHookEx, it seems it can't catch so much infor, only LButton RButton Down/Up? What function should I use or maybe I should ask how to hook Dialog box message Proc? Thanks
4
1466
by: Mike Bulava | last post by:
I know this has to be something stupid I'm forgetting. Any time a mouse button is clicked (any mouse button) I want get all the information about where the Pointer is, what button was clicked, etc even if it not over a form my app created. How can I do this. Like I said I know this is simple I just can't remember it.
6
8769
by: Ahmed | last post by:
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.
3
2881
by: Iosy | last post by:
Hi all, I'm working in a application where I need to detect when the mouse is inactive outside my form. I mean, I want to detect if the mouse hasn't move in the last X seconds (2 por example) and in case that it hasn't, show a menu. Thanks
3
10934
by: harvie wang | last post by:
Hi, I create a system mouse hook, to get mouse position and click events. use GetDesktopWiindow and WindowFromPoint(x,y) to get window handle in my hook proc. Click mouse on desktop window and print the window handle which i got in hook proc. GetDesktopwindow() == 65557; WindowFromPoint(x,y) == 65700; but when i use spy++ to get the desktop window handle, it's return 0x100A4
1
1400
by: Tom Rahav | last post by:
Hello, I try to develop application that runs in the background and suppose to display a small form with menu whenever the user clicks the middle mouse button (also when my application is not the active one). I have found a nice way to do it with hooking mouse events and reactring accordingly. but I'm affriad that this method is a performances killer for the OS. Is there a better way to do it? How "killer" is my way anyway? Thanks!
22
6432
by: schneider | last post by:
I need to hook the system mouse down event. I'm trying to replicate how a context menu hides when the mouse clicks outside of the control. Thanks, Schneider
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.