C#模拟鼠标点击

using System.Runtime.InteropServices;
#region API
[DllImport(
"user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
[Flags]
enum MouseEventFlag : uint
{
Move
= 0x0001,
LeftDown
= 0x0002,
LeftUp
= 0x0004,
RightDown
= 0x0008,
RightUp
= 0x0010,
MiddleDown
= 0x0020,
MiddleUp
= 0x0040,
XDown
= 0x0080,
XUp
= 0x0100,
Wheel
= 0x0800,
VirtualDesk
= 0x4000,
Absolute
= 0x8000
}
#endregion
//以上代码放在Class 任意处
mouse_event(MouseEventFlag.Move, 0, 0, 0, UIntPtr.Zero)

//执行左键按下
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);

//执行左键松开
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
//完成一个单击动作
//之后执行以上代码便可模似鼠标单击一次
posted @ 2011-06-04 23:30  Bruce.X.He  阅读(982)  评论(0编辑  收藏