From 3a9785573ea3cacab13dafeaa181db0a2be5a1b1 Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Thu, 29 May 2025 12:19:24 +0700 Subject: [PATCH] Upload files Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- .gitignore | 5 ++ App.config | 6 ++ MouseSimulator.csproj | 53 ++++++++++++++++++ MouseSimulator.sln | 25 +++++++++ Program.cs | 112 +++++++++++++++++++++++++++++++++++++ Properties/AssemblyInfo.cs | 33 +++++++++++ 6 files changed, 234 insertions(+) create mode 100644 .gitignore create mode 100644 App.config create mode 100644 MouseSimulator.csproj create mode 100644 MouseSimulator.sln create mode 100644 Program.cs create mode 100644 Properties/AssemblyInfo.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93621e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs +bin/ +obj/ +packages/ +*.csproj.user diff --git a/App.config b/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MouseSimulator.csproj b/MouseSimulator.csproj new file mode 100644 index 0000000..85bc7aa --- /dev/null +++ b/MouseSimulator.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {2FB36A1D-BD2B-47D9-9699-4BD158A9048C} + Exe + MouseSimulator + MouseSimulator + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MouseSimulator.sln b/MouseSimulator.sln new file mode 100644 index 0000000..39129ca --- /dev/null +++ b/MouseSimulator.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MouseSimulator", "MouseSimulator.csproj", "{2FB36A1D-BD2B-47D9-9699-4BD158A9048C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2FB36A1D-BD2B-47D9-9699-4BD158A9048C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FB36A1D-BD2B-47D9-9699-4BD158A9048C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FB36A1D-BD2B-47D9-9699-4BD158A9048C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FB36A1D-BD2B-47D9-9699-4BD158A9048C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1FE8367E-2F14-4F26-873F-D5093BAE851D} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..79bf01e --- /dev/null +++ b/Program.cs @@ -0,0 +1,112 @@ +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 void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo); + + [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; + } + + // Константы для mouse_event + /* + private const uint MOUSEEVENTF_LEFTDOWN = 0x0002; + private const uint MOUSEEVENTF_LEFTUP = 0x0004; + private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008; + private const uint MOUSEEVENTF_RIGHTUP = 0x0010; + private const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020; + private const uint MOUSEEVENTF_MIDDLEUP = 0x0040; + private const uint MOUSEEVENTF_WHEEL = 0x0800; + private const uint MOUSEEVENTF_HWHEEL = 0x01000; + private const uint MOUSEEVENTF_MOVE = 0x0001; + private const uint MOUSEEVENTF_ABSOLUTE = 0x8000; + */ + + // Перемещение курсора + public static void MoveTo(int x, int y) + { + SetCursorPos(x, y); + } + + // Поулчение позиции курсора + public static POINT GetPosition() + { + POINT point; + if (GetCursorPos(out point)) + return point; + return default; + } + + /* + // Левый клик + public static void LeftClick() + { + mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); + } + + // Правый клик + public static void RightClick() + { + mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); + } + + // Прокрутка колеса + public static void MouseWheel(int delta) + { + mouse_event(MOUSEEVENTF_WHEEL, 0, 0, (uint)delta, 0); + } + + // Горизонтальная прокрутка + public static void MouseHWheel(int delta) + { + mouse_event(MOUSEEVENTF_HWHEEL, 0, 0, (uint)delta, 0); + } + */ + } + + 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); + } + } + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cfb70cc --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанные с этой сборкой. +[assembly: AssemblyTitle("MouseSimulator")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MouseSimulator")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// из модели COM задайте для атрибута ComVisible этого типа значение true. +[assembly: ComVisible(false)] + +// Следующий GUID представляет идентификатор typelib, если этот проект доступен из модели COM +[assembly: Guid("2fb36a1d-bd2b-47d9-9699-4bd158a9048c")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Номер редакции +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]