本文介绍了我目前正在制作一个 Autoclicker,到目前为止它已经取得了半成功.我需要帮助介绍切换键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试添加一个切换键并让它保持点击,这样当我切换它并按住左键点击时,它就会开始点击.目前它会启动,当我将 CPS 居中时,它会点击,但不会停止.它会连续点击.

At the moment I'm trying to add a toggle key and make it hold to click, so that when I toggle it and hold down left click, it starts clicking. Currently it boots up and when I center the CPS it clicks, but it doesn't stop. It'll click continuously.

#include <iostream>
#include <windows.h>

using namespace std;


int x = 0, y = 0, cps;
bool click = false;

void Menu()
{
    cout << "Add CPS (click per second):" << endl;
    cin >> cps;
}
void Clicker()
{
    while (1)
    {
        if (GetAsyncKeyState(VK_LBUTTON)) 
        {
            click = true;
        }

        if (GetAsyncKeyState(VK_RBUTTON)) 
        {
            click = false;
        }

        if (click == true)
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
            Sleep(1000 / cps);
        }
    }
}
int main()
{
    Menu();
    Clicker();
}

推荐答案

请检查以下代码,看看是否有帮助:

Please check the following code to see if it helps:

void Clicker()
{
    while (1)
    {
        if (GetAsyncKeyState(VK_LBUTTON) & 0x8000 && !click) //Capture that auto click start condition.
        {
            click = true;
        }
        else
        {
            click = false;
        }

        while (click)
        {
            if (GetAsyncKeyState(VK_RBUTTON) & 0x8000) //Capture the stop condition.
            {
                break;
            }
            mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
            Sleep(1000 / cps);
        }
    }
}

GetAsyncKeyState 返回值:

如果设置了最高有效位,则密钥处于关闭状态.

这篇关于我目前正在制作一个 Autoclicker,到目前为止它已经取得了半成功.我需要帮助介绍切换键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 09:11