-
Notifications
You must be signed in to change notification settings - Fork 3
/
Debug.cpp
210 lines (203 loc) · 4.14 KB
/
Debug.cpp
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
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
int Mode, Start, Continue, Space, Speed;
char ch;
short vkCode;
HWND hwnd;
int keydown, keyup;
int get_Lparam(int vk, bool flag)
{
int scanCode = MapVirtualKey(vk, MAPVK_VK_TO_VSC);
return flag | (scanCode << 16) | (flag << 30) | (flag << 31);
}
void getWindow()
{
while (true)
{
if (GetAsyncKeyState(VK_LCONTROL) && GetAsyncKeyState(VK_LMENU))
{
hwnd = GetForegroundWindow();
if (hwnd != NULL)
{
char title[50];
::GetWindowTextA(hwnd, title, sizeof(title));
system("cls");
cout << "捕获成功!窗口名称:" << endl;
cout << title << endl;
}
else
cout << "捕获失败!请重试!" << endl;
cout << endl;
return;
}
Sleep(1);
}
}
void Input()
{
cout << "[1]左键连点 [2]左键长按" << endl;
cout << "[3]右键连点 [4]右键长按" << endl;
cout << "[5]字母键长按 [6]空格长按" << endl;
cout << "请输入数字选择操作" << endl << "<< ";
cin >> Mode;
if (Mode == 1 || Mode == 3)
{
cout << "请输入连点速度(毫秒)" << endl << "<< ";
cin >> Speed;
}
else if (Mode == 5)
{
cout << "请输入字母" << endl << "<< ";
cin >> ch;
}
else if (Mode == 6)
ch = ' ';
cout << "多少时间后后开始操作(毫秒)" << endl << "<< ";
cin >> Start;
cout << "操作持续多少时间后暂停(毫秒,-1为无限)" << endl << "<< ";
cin >> Continue;
cout << "暂停后间隔多少时间继续操作(毫秒)" << endl << "<< ";
cin >> Space;
if (Mode >= 5)
{
vkCode = LOBYTE(VkKeyScan(ch));
keydown = get_Lparam(vkCode, false);
keyup = get_Lparam(vkCode, true);
}
}
bool sleep(int t)
{
long now = clock();
while (clock() - now < t)
{
Sleep(1);
if (GetAsyncKeyState(VK_RCONTROL))
return true;
}
return false;
}
void Do()
{
if (sleep(Start))
return;
long tstart = clock();
if (Mode == 1)
while (true)
{
SendMessage(hwnd, WM_LBUTTONDOWN, 0, 0);
SendMessage(hwnd, WM_LBUTTONUP, 0, 0);
if (sleep(Speed))
return;
if (Continue != -1 && clock() - tstart >= Continue)
{
if (sleep(Space))
return;
tstart = clock();
}
if (GetAsyncKeyState(VK_RCONTROL))
return;
}
if (Mode == 2)
{
SendMessage(hwnd, WM_LBUTTONDOWN, 0, 0);
while (true)
{
if (Continue != -1 && clock() - tstart >= Continue)
{
SendMessage(hwnd, WM_LBUTTONUP, 0, 0);
if (sleep(Space))
return;
SendMessage(hwnd, WM_LBUTTONDOWN, 0, 0);
tstart = clock();
}
if (GetAsyncKeyState(VK_RCONTROL))
{
SendMessage(hwnd, WM_LBUTTONUP, 0, 0);
return;
}
Sleep(1);
}
}
if (Mode == 3)
while (true)
{
SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0);
SendMessage(hwnd, WM_RBUTTONUP, 0, 0);
if (sleep(Speed))
return;
if (Continue != -1 && clock() - tstart >= Continue)
{
if (sleep(Space))
return;
tstart = clock();
}
if (GetAsyncKeyState(VK_RCONTROL))
return;
}
if (Mode == 4)
{
SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0);
while (true)
{
if (Continue != -1 && clock() - tstart >= Continue)
{
SendMessage(hwnd, WM_RBUTTONUP, 0, 0);
if (sleep(Space))
return;
SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0);
tstart = clock();
}
if (GetAsyncKeyState(VK_RCONTROL))
{
SendMessage(hwnd, WM_RBUTTONUP, 0, 0);
return;
}
Sleep(1);
}
}
if (Mode >= 5)
{
PostMessage(hwnd, WM_KEYDOWN, vkCode, keydown);
while (true)
{
if (Continue != -1 && clock() - tstart >= Continue)
{
PostMessage(hwnd, WM_KEYUP, vkCode, keyup);
if (sleep(Space))
return;
PostMessage(hwnd, WM_KEYDOWN, vkCode, keydown);
tstart = clock();
}
if (GetAsyncKeyState(VK_RCONTROL))
{
PostMessage(hwnd, WM_KEYUP, vkCode, keyup);
return;
}
Sleep(1);
}
}
}
int main()
{
system("title Minecraft-AFK By Cheny");
system("mode con cols=45 lines=25");
cout << "请前往指定窗口按下左Ctrl+左Alt捕获窗口" << endl;
while (hwnd == NULL)
getWindow();
Input();
cout << endl << ">>>请在任意位置按下右Alt开始操作<<<" << endl;
cout << ">>>任意位置按下右Ctrl结束<<<" << endl << endl;
while (true)
{
if (GetAsyncKeyState(VK_RMENU))
{
cout << "\r开始操作!按右Ctrl可结束!";
system("color 03");
Do();
cout << "\r操作结束!按右Alt重新开始!";
system("color 07");
}
Sleep(1);
}
}