Mouse question/help  
Author Message

PostPosted: Visual C# General, Mouse question/help Top

Hello, I am doing some research for a university and need some help with mouse movements. I need to be able to track the mouse no matter what window it is in. I have searched for this information extensively and have not really found a good answer. Idealy I would like to know for instance, if it is in Internet Explorer, where it is located i.e if it is click on the file button at the top for instance. For now however I just want to be able to have the mouse move outside my window and for me to be able to still ascertain its coordinates. Do I need to write some sort of horrible assembler program to get direct mouse input Also I am using 'forms'.

Visual C#14  

PostPosted: Visual C# General, Mouse question/help Top


PostPosted: Visual C# General, Mouse question/help Top

not entirely sure on how to detect what "Window" you will be on however to get the mouse co-ordinates, use the Cursor.Position.ToString() to get the x,y co-ords. So you can place a label and a timer on the form, set the timer interval to say 100ms then on this timer tick event, do:

this.theLabel.Text = Cursor.Position.ToString();

this should update the status on every tick event (be sure to start the timer too!)


if you need to move the mouse programmatically, you can also do this by creating a new position:

Cursor.Position = new Point (x, y);

where x and y are the co-ords of where you want the mouse to be placed on the screen