Files
better-genshin-impact/Vision.Recognition/Helper/Simulator/MouseEventSimulator.cs
2023-09-23 12:54:16 +08:00

57 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Vanara.PInvoke;
namespace Vision.Recognition.Helper.Simulator
{
public class MouseEventSimulator
{
public static void Move(int x, int y)
{
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_ABSOLUTE | User32.MOUSEEVENTF.MOUSEEVENTF_MOVE,
x * 65535 / PrimaryScreen.DESKTOP.Width, y * 65535 / PrimaryScreen.DESKTOP.Height,
0, 0);
}
public static void LeftButtonDown()
{
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
}
public static void LeftButtonUp()
{
User32.mouse_event(User32.MOUSEEVENTF.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
public static bool Click(int x, int y)
{
if (x == 0 && y == 0)
{
return false;
}
Move(x, y);
LeftButtonDown();
Thread.Sleep(20);
LeftButtonUp();
return true;
}
public static bool Click(Point point)
{
return Click((int)point.X, (int)point.Y);
}
public static bool DoubleClick(Point point)
{
Click(point);
Thread.Sleep(200);
return Click(point);
}
}
}