C# 利用API操作鼠标 -- MouseAPI

public class MouseAPI
{
[DllImport(
"user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport(
"user32.dll")]
static extern void Mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
[Flags]
public 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
}
public void SetCursorPosition(int x, int y)
{
SetCursorPos(x, y);
}
public void MouseEvent(MouseEventFlag flag)
{
Mouse_event(flag,
0, 0, (uint)0, (UIntPtr)0);
}
}
posted @ 2011-04-21 16:47  把爱延续  阅读(923)  评论(3编辑  收藏  举报