您的位置:首页 > 移动开发 > Unity3D

Unity获取系统鼠标

2016-07-25 16:11 531 查看
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, int cButtons, uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
private const int MOUSEEVENTF_MOVE = 0x01;
private const int MOUSEEVENTF_WHEEL = 0x800;
public void MouseMove(Vector deltaPosition, float speed)
{
mouse_event(MOUSEEVENTF_MOVE, (uint)(deltaPosition.x * speed), (uint)(deltaPosition.y * speed), 0, 0);
}
public void LeftButtonDown()
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
}
public void LeftButtonUp()
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
Vector currentMousePosition = Vector.Zero;
Vector prevFrameMousePosition = Vector.Zero;
private int currentHandingHandID = -1;
private bool mouseLeftButtonPressed = false;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息