-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
86 lines (67 loc) · 2.42 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MoveCursorWindowless
{
static class Program
{
[DllImport("User32.Dll")]
static extern long SetCursorPos(int x, int y);
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(out Point lpPoint);
static Timer Timer = new Timer { Interval = 30_000 };
static Point _previousPosition;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
GetCursorPos(out _previousPosition);
Timer.Tick += OnTimerTick;
Timer.Start();
Application.ApplicationExit += OnApplicationExit;
Application.Run(new MoveCursorAppContext());
}
private static void OnTimerTick(object sender, EventArgs e)
{
GetCursorPos(out Point currentPosition);
if (currentPosition == _previousPosition)
{
MakeMove();
}
_previousPosition = currentPosition;
}
private static void MakeMove()
{
var w = Screen.PrimaryScreen.Bounds.Width;
var h = Screen.PrimaryScreen.Bounds.Height;
var centerX = w / 2;
var centerY = h / 2;
var radius = 50;
for (int i = 0; i < 360; i++)
{
var p = PointOnCircle(radius, i, new PointF(centerX, centerY));
SetCursorPos((int)p.X, (int)p.Y);
System.Threading.Thread.Sleep(2);
}
}
private static PointF PointOnCircle(float radius, float angle, PointF origin)
{
// Convert from degrees to radians via multiplication by PI/180
var x = (float)(radius * Math.Cos(angle * Math.PI / 180F)) + origin.X;
var y = (float)(radius * Math.Sin(angle * Math.PI / 180F)) + origin.Y;
return new PointF(x, y);
}
private static void OnApplicationExit(object sender, EventArgs e)
{
Application.ApplicationExit -= OnApplicationExit;
Timer.Tick -= OnTimerTick;
Timer.Dispose();
}
}
}