C++鼠标连点器

C++鼠标连点器

Zephyr

前几天LOL PBE 出现了BUG,可以无限刷宝箱。但是要鼠标连续4下才能刷到。于是我就想到用鼠标连点器来自动刷。

经过几次搜索,我在知乎上找到了能够自己设定鼠标坐标的连点器,我稍微修改了一下。

最后,我也成功刷了1W多个宝箱。

下面是原代码

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
#include "iostream"
#include "conio.h"
#include "ctime"
#include "vector"
#include "string"
#include "windows.h"

void set_cursor(bool hide){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = hide;
SetConsoleCursorInfo(handle, &CursorInfo);
}

void gotoxy(int x, int y){
COORD c = {(SHORT)x, (SHORT)y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

void setmode(){
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin, &mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
}

class Click{
public:
int x, y;
int delay;
int button_down, button_up;
std::string msg;
};

int main(){
setmode();
std::cout << "欢迎使用鼠标连点器。\n\n" << std::endl;
_ReStart_:
std::system("mode con cols=40 lines=15");
set_cursor(true);
SetWindowPos(GetConsoleWindow(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
std::cout << "请选择模式:\n" << " 1.点击位置为鼠标指针,鼠标左/右键点击\n" << " 2.点击位置固定循环,鼠标左/右键点击\n" << " 0.退出\n";
int ch = _getch();
while(ch < '0' || ch > '2') ch = _getch();
std::system("cls");
set_cursor(false);
if (ch == '1'){
set_cursor(true);
std::cout << "配置:";
std::cout << "请输入每秒钟的点击次数(1—1000):" << std::endl;
int spd;
std::cin >> spd;
std::cout << "\n请选择点击的键(0左键,1右键):" << std::endl;
ch = _getch();
while(ch < '0' || ch > '1') ch = _getch();
int CLICK_BUTTON_DOWN = (ch == '0' ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN);
int CLICK_BUTTON_UP = (ch == '0' ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP);
std::system("cls");
int cont = true, lst_tim = clock();
set_cursor(false);
while(true){
gotoxy(0, 0);
std::string t;
std::string y;
t=cont ? "运行中" : "已暂停";
y=cont ? "暂停" : "继续";
std::cout << "\n\n连点器" << t << std::endl;
std::cout << "\n速度:" << spd << "次/秒" << std:: endl;
std::cout << " \n空格键:" << y << std::endl;
std::cout << " \nEsc键:退出" << std::endl;
SetWindowPos(GetConsoleWindow(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); // 窗口置顶
if(_kbhit()){
int ch = _getch();
if(ch == 27){
break;
}else if(ch == ' '){
cont = !cont;
}
}else{
if(cont)
{
if(clock() - lst_tim >= 1.0 / spd * CLOCKS_PER_SEC){
lst_tim = clock();
POINT pt;
GetCursorPos(&pt);
mouse_event(CLICK_BUTTON_DOWN, 0, 0, 0, 0);
mouse_event(CLICK_BUTTON_UP, 0, 0, 0, 0);
}
}
}
}
}
else if(ch == '2'){
std::cout << "请输入您要点击的位置个数:" << std::endl;
int times;
std::cin >> times;
std::vector<Click> ps;
set_cursor(true);
for(int i = 1; i <= times; i++){
std::system("cls");
std::cout << "将鼠标移动到第" << i << "个位置上后按下空格:" << std::endl;
while (_getch() != ' ') {}
POINT p;
GetCursorPos(&p);
ps.push_back({p.x, p.y, 0, 0, 0, ""});
std::cout << "\n需要按下的键(0左键,1右键):" << std::endl;
char ch = _getch();
while (ch < '0' || ch > '1') ch = _getch();
ps.back().button_down = (ch == '0' ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN);
ps.back().button_up = (ch == '0' ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP);
std::cout << "\n在上一次点击后需要等待多少毫秒:" << std::endl;
int delay;
std::cin >> delay;
ps.back().delay = delay;
std::cout << "\n附加描述(可不填):" << std::endl;
char msg[10000];
gets(msg);
gets(msg);
ps.back().msg = msg;
}
int cont = true;
int now = 0;
int lst_tim = clock();
std::system("cls");
set_cursor(false);
while(true){
gotoxy(0, 0);
std::string e;
std::string r;
e=cont ? "运行中" : "已暂停";
r=cont ? "暂停" : "继续";
std::cout << "连点器" << e << std::endl;
std::cout << "当前位置描述:" << ps[now].msg.c_str() << std::endl;
std::cout << "需要等待:" << ps[now].delay << "毫秒"<< std::endl;
std::cout << "点击按键:" << (ps[now].button_down == MOUSEEVENTF_LEFTDOWN ? "右" : "左" )<< "键\n" << std::endl;
std::cout << " 空格键:" << r << std::endl;
std::cout << " Esc键:退出" << std::endl;
SetWindowPos(GetConsoleWindow(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); // 窗口置顶
if(_kbhit()){
int ch = _getch();
if(ch == 27){
break;
} else if(ch == ' '){
cont = !cont;
}
}else {
if(cont){
if(clock() - lst_tim > ps[now].delay){
lst_tim = clock();
POINT pt;
GetCursorPos(&pt);
SetCursorPos(ps[now].x, ps[now].y);
mouse_event(ps[now].button_down, 0, 0, 0, 0);
mouse_event(ps[now].button_up, 0, 0, 0, 0);
SetCursorPos(pt.x, pt.y);
if(now + 1 == (int)ps.size()) now = 0;
else
now = now + 1;
}
}
}
}
}else
return 0;
std::system("cls");
std::cout << "欢迎回来!\n\n" <<std::endl;
goto _ReStart_;
return 0;
}
On this page
C++鼠标连点器