-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
240 lines (214 loc) · 8.18 KB
/
Main.cs
File metadata and controls
240 lines (214 loc) · 8.18 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Auto_Clicker
{
public partial class Main : Form
{
List<Content> contents = new List<Content>();
int count = 0;
public void drawContents()
{
flow.Controls.Clear();
foreach (var now in contents)
{
flow.Controls.Add(new Panel
{
Name = $"{flow.Controls.Count}",
Width = 129,
Height = 55,
BackColor = System.Drawing.SystemColors.ControlDark,
BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
});
var cont = flow.Controls[flow.Controls.Count - 1];
string content = "Unknown";
if (now.type == 0)
{
if (now.mouse == 0) content = "좌클릭";
else if (now.mouse == 1) content = "우클릭";
}
else if (now.type == 1)
{
content = $"키보드 {now.key}";
}
cont.Controls.AddRange(new Control[] {
new Label
{
Name = $"{flow.Controls.Count - 1}",
Text = content,
Width = 79,
Height = 19,
TextAlign = System.Drawing.ContentAlignment.MiddleCenter,
Location = new Point(4, 5)
},
new Button
{
Name = $"{flow.Controls.Count - 1}",
Text = "속성",
Location = new System.Drawing.Point(88, 3),
Size = new System.Drawing.Size(38, 23),
UseVisualStyleBackColor = true
},
new Button
{
Name = $"{flow.Controls.Count - 1}",
Text = "삭제",
Location = new System.Drawing.Point(45, 27),
Size = new System.Drawing.Size(39, 23),
UseVisualStyleBackColor = true
},
new Button
{
Name = $"{flow.Controls.Count - 1}",
Text = "<",
Location = new System.Drawing.Point(4, 27),
Size = new System.Drawing.Size(20, 23),
UseVisualStyleBackColor = true
},
new Button
{
Name = $"{flow.Controls.Count - 1}",
Text = ">",
Location = new System.Drawing.Point(104, 27),
Size = new System.Drawing.Size(20, 23),
UseVisualStyleBackColor = true
}
});
(cont.Controls[1] as Button).Click += (object sender, EventArgs e) =>
{
//속성버튼
};
(cont.Controls[2] as Button).Click += (object sender, EventArgs e) =>
{
//삭제버튼
contents.RemoveAt(int.Parse((sender as Button).Name));
drawContents();
};
(cont.Controls[3] as Button).Click += (object sender, EventArgs e) =>
{
//좌로이동
int n = int.Parse((sender as Button).Name);
if (0 < n)
{
var tmp = contents[n];
contents[n] = contents[n - 1];
contents[n - 1] = tmp;
}
drawContents();
};
(cont.Controls[4] as Button).Click += (object sender, EventArgs e) =>
{
//우로이동
int n = int.Parse((sender as Button).Name);
if (n < contents.Count - 1)
{
var tmp = contents[n];
contents[n] = contents[n + 1];
contents[n + 1] = tmp;
}
drawContents();
};
}
}
int StartKeyNumber = 3;
int StopKeyNumber = 4;
bool isClicking = false;
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
const int HOTKEY_ID = 31197;
const int WM_HOTKEY = 0x0312;
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
protected override void WndProc(ref Message message)
{
switch (message.Msg)
{
case WM_HOTKEY:
Keys key = (Keys)(((int)message.LParam >> 16) & 0xFFFF);
KeyModifiers modifier = (KeyModifiers)((int)message.LParam & 0xFFFF);
if (KeyModifiers.None == modifier && Keys.F1 + StartKeyNumber - 1 == key)
isClicking = true;
if (KeyModifiers.None == modifier && Keys.F1 + StopKeyNumber - 1 == key)
isClicking = false;
break;
}
base.WndProc(ref message);
}
public Main()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.comboBox1.Text = "F3";
this.comboBox2.Text = "F4";
drawContents();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
StartKeyNumber = int.Parse(this.comboBox1.Text.Substring(1));
UnregisterHotKey(this.Handle, HOTKEY_ID);
RegisterHotKey(this.Handle, HOTKEY_ID, KeyModifiers.None, Keys.F1 + StartKeyNumber - 1);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
StopKeyNumber = int.Parse(this.comboBox2.Text.Substring(1));
UnregisterHotKey(this.Handle, HOTKEY_ID + 1);
RegisterHotKey(this.Handle, HOTKEY_ID + 1, KeyModifiers.None, Keys.F1 + StopKeyNumber - 1);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.timer1.Interval = 1000 / int.Parse(textBox1.Text);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (isClicking)
{
int Xposition = MousePosition.X;
int Yposition = MousePosition.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN, Xposition, Yposition, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, Xposition, Yposition, 0, 0);
}
}
private void addContent_Click(object sender, EventArgs e)
{
contents.Add(new Content(count++));
drawContents();
}
private void clearContents_Click(object sender, EventArgs e)
{
contents.Clear();
drawContents();
}
}
class Content
{
public int type = 0; // 마우스=0 키보드=1
public int mouse = 0; // 좌클릭=0 우클릭=1
public Keys key = Keys.Space; //키보드
public int id = 0;
public Content(int nid)
{
id = nid;
}
}
}