With this class you can easy control the mouse from c#. For the click event it's use the P/Invoke of mouse_event API. To move the cursor positon use directly the managed code.
(Only for x86.)
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MouseMov
{
public class MouseHook
{
[DllImport("user32.dll")]
private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);
private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
internal static void SendDoubleClick()
{
SendClick();
SendClick();
}
internal static void SendClick()
{
SendDown();
SendUp();
}
internal static void SendUp()
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr());
}
private void MoveMouse(Point p)
{
Cursor.Position = new Point(Cursor.Position.X + p.X, Cursor.Position.Y + p.Y);
}
internal static void SendDown()
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr());
}
}
}
Have fun.
Visualizzazione post con etichetta Cursor Position. Mostra tutti i post
Visualizzazione post con etichetta Cursor Position. Mostra tutti i post
martedì 4 novembre 2008
Iscriviti a:
Post (Atom)

