怎样使用C#.net去解决远程控制别机鼠标//
有案例的请借用下。。
急用///// <summary>
/// API类
/// </summary>
public class Api
{
/// <summary>
/// 模拟鼠标事件的函数模型
/// </summary>
/// <param name="flags"></param>
/// <param name="dx"></param>
/// <param name="dy"></param>
/// <param name="dwData"></param>
/// <param name="dwExtraInfo"></param>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern void mouse_event(int flags, int dx, int dy, int dwData, int dwExtraInfo);
/// <summary>
/// 设置光标到指定位置的函数模型
/// </summary>
/// <param name="X"></param>
/// <param name="Y"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetCursorPos(int X, int Y);
/// <summary>
/// 模拟键盘事件的函数模型
/// </summary>
/// <param name="bVk"></param>
/// <param name="bScan"></param>
/// <param name="dwFlags"></param>
/// <param name="dwExtraInfo"></param>
[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "keybd_event")]
public static extern void keybd_event(
byte bVk,
byte bScan,
int dwFlags,
int dwExtraInfo
);
}
/// <summary>
/// 鼠标Hook类
/// </summary>
public class MouseHook
{
/// <summary>
/// 鼠标事件枚举
/// </summary>
public enum MouseEventFlag
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
/// <summary>
/// 委托-鼠标按键触发
/// </summary>
/// <param name="flags"></param>
/// <param name="dx"></param>
/// <param name="dy"></param>
/// <param name="dwData"></param>
/// <param name="dwExtraInfo"></param>
public delegate void DoMouseButtons(int flags, int dx, int dy, int dwData, int dwExtraInfo);
/// <summary>
/// 委托-鼠标移动触发
/// </summary>
/// <param name="X"></param>
/// <param name="Y"></param>
/// <returns></returns>
public delegate bool DoMouseMove(int X, int Y);
/// <summary>
/// 模拟鼠标按钮按下的事件
/// </summary>
private event DoMouseButtons MouseButton;
/// <summary>
/// 模拟鼠标移动的事件
/// </summary>
private event DoMouseMove MouseMove;
/// <summary>
/// 创建鼠标钩子的实例
/// </summary>
public MouseHook()
{
MouseButton += new DoMouseButtons(Api.mouse_event);
MouseMove += new DoMouseMove(Api.SetCursorPos);
}
/// <summary>
/// 控制鼠标执行相应操作
/// </summary>
/// <param name="MEvent">指定的鼠标事件</param>
public void MouseWork(MouseEvent MEvent)
{
switch (MEvent.Type)
{
case MouseEventType.MouseMove:
MouseMove(MEvent.X, MEvent.Y);
break;
case MouseEventType.MouseLeftDown:
MouseMove(MEvent.X, MEvent.Y);
MouseButton((int)MouseEventFlag.LeftDown, MEvent.X, MEvent.Y, 0, 0);
break;
case MouseEventType.MouseLeftUp: