[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;
Unity获取系统鼠标
最新推荐文章于 2023-02-16 17:16:21 发布