-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathForm1.cs
More file actions
135 lines (124 loc) · 4.1 KB
/
Copy pathForm1.cs
File metadata and controls
135 lines (124 loc) · 4.1 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using WindowsInput.Native;
using WindowsInput;
namespace MouseSimulator
{
public partial class Form1 : Form
{
private Random rand = new Random();
private Logger logger = new Logger();
private InputSimulator inputSimilator = new InputSimulator();
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern void SetCursorPos(int x, int y);
private void Form1_Load(object sender, EventArgs e)
{
cmbKey.SelectedIndex = 0;
cmbPeriod.SelectedIndex = 1;
logger.write(txtLog, "Program loaded");
}
private void timerMain_Tick(object sender, EventArgs e)
{
if (chkMouse.Checked)
{
int x = rand.Next(0, 800);
int y = rand.Next(0, 600);
SetCursorPos(x, y);
logger.write(txtLog, "Moving cursor to: x = " + x.ToString() + ", y = " + y.ToString());
}
if (chkKeyPress.Checked)
{
inputSimilator.Keyboard.KeyPress(getKey());
logger.write(txtLog, "Pressed [" + cmbKey.Text + "] button");
}
}
private void button1_Click(object sender, EventArgs e)
{
if (chkMouse.Checked || chkKeyPress.Checked)
{
timerMain.Interval = Convert.ToInt32(numPeriod.Value) * getIntervalMultiplier();
logger.write(txtLog, "Setting period to " + numPeriod.Value.ToString() + " " + cmbPeriod.Text);
timerMain.Enabled = true;
logger.write(txtLog, "Simulation started!");
changeUiState(false);
}
else
{
logger.write(txtLog, "Error: You need select at least one action to start");
}
}
private void button2_Click(object sender, EventArgs e)
{
timerMain.Enabled = false;
changeUiState(true);
logger.write(txtLog, "Simulation stopped!");
}
private void changeUiState(Boolean active)
{
btnStop.Enabled = !active;
btnStart.Enabled = active;
chkKeyPress.Enabled = active;
chkMouse.Enabled = active;
cmbKey.Enabled = active;
cmbPeriod.Enabled = active;
numPeriod.Enabled = active;
}
private int getIntervalMultiplier()
{
switch (cmbPeriod.SelectedIndex)
{
case 0:
return 1;
case 1:
return 1000;
case 2:
return 60 * 1000;
case 3:
return 60 * 60 * 1000;
default:
return 1;
}
}
private VirtualKeyCode getKey()
{
switch (cmbKey.SelectedIndex)
{
case 1:
return VirtualKeyCode.LWIN;
case 2:
return VirtualKeyCode.RWIN;
case 3:
return VirtualKeyCode.F1;
case 4:
return VirtualKeyCode.F2;
case 5:
return VirtualKeyCode.F3;
case 6:
return VirtualKeyCode.F4;
case 7:
return VirtualKeyCode.F5;
case 8:
return VirtualKeyCode.F6;
case 9:
return VirtualKeyCode.F7;
case 10:
return VirtualKeyCode.F8;
case 11:
return VirtualKeyCode.F9;
case 12:
return VirtualKeyCode.F10;
case 13:
return VirtualKeyCode.F11;
case 14:
return VirtualKeyCode.F12;
default:
return VirtualKeyCode.LWIN;
}
}
}
}