Files
MouseSimulator/Program.cs
2025-05-29 12:20:48 +07:00

69 lines
2.0 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Threading;
using static MouseSimulator.MouseSimulator;
namespace MouseSimulator
{
public class MouseSimulator
{
// Импорт необходимых функций из user32.dll
[DllImport("user32.dll")]
private static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int x, int y);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
// Перемещение курсора
public static void MoveTo(int x, int y)
{
SetCursorPos(x, y);
}
// Поулчение позиции курсора
public static POINT GetPosition()
{
if (GetCursorPos(out POINT point))
return point;
return default;
}
}
internal class Program
{
static void Main(string[] args)
{
Console.CancelKeyPress += (sender, eventArgs) => {
Console.WriteLine("Сигнал выхода получен. Завершаем процесс...");
Environment.Exit(0);
};
int stepToMove = 1;
int[][] steps =
{
// x y
new int[] { 0, -stepToMove },
new int[] { 0, stepToMove },
new int[] { stepToMove, 0 },
new int[] { -stepToMove, 0 },
};
Console.WriteLine("Чтобы закрыть программу нажмите Ctrl + C");
while (true)
{
foreach (int[] step in steps)
{
POINT currentPosition = GetPosition();
MoveTo(currentPosition.X + step[0], currentPosition.Y + step[1]);
Thread.Sleep(1000);
}
}
}
}
}