How move the mouse with API function

  • Thread starter Thread starter nicolas
  • Start date Start date
N

nicolas

Hello,

I would like to move the mouse with API function "SetCursorPos". But i don't
know how to integrate this API function in my Form.

Thx for your Help.
 
Since you have posted this requirement of yours in this newsgroup I assume you want to do this cursor manipulation from a managed application. If that's the case you'll delighted to know that most of the cursor API's have a counterpart in the managed world which is mentioned below. There's a dedicated type defined in System.Windows.Forms namespace specifically this purpose - Cursor type.
Win32 to .NET FW API Map
Win32 function Description .NET Framework API
ClipCursor Confines the cursor to a rectangular area on the screen. System.Windows.Forms.Cursor.Clip
CopyCursor Copies the specified cursor. System.Windows.Forms.Cursor.CopyHandle
CreateCursor Creates a cursor having the specified size, bit patterns, and hot spot. System.Windows.Forms.Cursor constructor
System.Windows.Forms.Cursor.Size
System.Windows.Forms.Cursor.Position
DestroyCursor Destroys a cursor. System.Windows.Forms.Cursor.Dispose
GetClipCursor Retrieves the screen coordinates of the rectangular area to which the cursor is confined. System.Windows.Forms.Cursor.Clip
GetCursor Retrieves a handle to the current cursor. System.Windows.Forms.Cursor.Handle
GetCursorInfo Retrieves information about the global cursor. System.Windows.Forms.Cursor.Position
System.Windows.Forms.SystemInformation.CursorSize
GetCursorPos Retrieves the cursor's position. System.Windows.Forms.Control.MousePosition
System.Windows.Forms.Cursor.Position
LoadCursor Loads a cursor resource from an executable file. System.Windows.Forms.Cursor constructor
LoadCursorFromFile Creates a cursor based on data contained in a file. System.Windows.Forms.Cursor constructor
SetCursor Sets the cursor shape. System.Windows.Forms.Cursor.Current
SetCursorPos Moves the cursor to the specified screen coordinates. System.Windows.Forms.Cursor.Position
ShowCursor Displays or hides the cursor. System.Windows.Forms.Cursor.Show
Windows.Forms.Cursor.Hide



In case you still want to do it the old, dirty and more efficient way, you will have to "PInvoke" it using InterOp.

DllImport("user32.dll")]
static extern bool SetCursorPos(int xPos, int yPos);

There's an excellent resource on the net for getting these method signatures right - PInvoke.Net, do have a look.

HTH, Metallikanz!
 
Back
Top