如何将动作绑定到键盘上的按钮?比如当你按F3时,开始点击很快,如果再按F3,程序会停止快速点击吗?
这段代码:
#include <iostream>
#include <Windows.h>
using namespace std;
void menu()
{
cout << "Press 'X' to enable and 'Z' to disable autoclicker\n";
}
void clicker()
{
bool click = false; //sets click to false
while (true)
{
if (GetAsyncKeyState('X')) //if X is pressed click = true
{
click = true;
}
else if (GetAsyncKeyState('Z')) //if 'Z' is pressed click = false
{
click = false;
}
if (click == true) // if click = true it will press the mouse button down and up really fast
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(1); //you can adjust the speed of the click here
}
}
}
int main()
{
menu();
clicker();
return 0;
}
试过:
void clicker() {
bool click = false;
while (true) {
if (GetAsyncKeyState('V')) {
click = true;
}
else if (GetAsyncKeyState('V')) {
click = false;
}
if (click == true) {
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(1);
}
}
}
它不起作用,它开始不停地点击,再次按 V 不会停止工作,我也尝试在这些行中将 V 更改为 X
if (GetAsyncKeyState('V')) {
click = true;
(这意味着当按下一个按钮时,答题器会启动)并且您需要按下另一个按钮才能停止,但这根本不是我想要的
稍微调整一下代码,结果如下:
出于您的目的,最好使用它
GetKeyState
,因为您需要一键打开/关闭它。有关GetKeyState和GetAsyncKeyState的更多信息。补充:另外,如果你正在为一些游戏编写点击器,那么我建议你设置点击之间的延迟,例如5毫秒,如下图:否则,游戏可能根本不会计算这些点击次数。