Loop repeated do statement with mouse left button variable click & hold

-2

Hey, currently testing a autoclicker for a few games, I am quite new to C++

How can I use left mouse button to run a do statement for the mouse click function without it stopping the do statement

I've tried different flags including :

input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP);

with mouse_event(MOUSEEVENTF)

do {
    if (GetAsyncKeyState(VK_LBUTTON) & 0x80000000) {
        enabled = true;

        while (GetAsyncKeyState(VK_LBUTTON) & 0x80000000) {
            Sleep(1000 / cps);
            INPUT input;
            input.type = INPUT_MOUSE;
            input.mi.dx = 0;
            input.mi.dy = 0;
            input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP);
            input.mi.mouseData = 0;
            input.mi.dwExtraInfo = NULL;
            input.mi.time = 0;
            SendInput(1, &input, sizeof(INPUT));

        }
    }


} while (true);

I am trying to make it so when you hold down left click, it runs the while statement containing the autoclicking function, without stopping the while statement due to repetitive clicking.

c++
winapi
asked on Stack Overflow Jan 19, 2019 by Taco Gamez • edited Jan 19, 2019 by πάντα ῥεῖ

1 Answer

0

There is something you should notice in your code:

First, How to judge the return value of GetAsyncKeyState()

If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.

the type of return value is SHORT which is 2 bytes. So try GetAsyncKeyState(VK_LBUTTON) & 0x8000 instead.

Second, How to use SendInput() to send different mouse state. You should create a new INPUT data to save different action, but not just combine all of them.

Code Sample:

do {
        if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
        {
            enabled = true;
            while (GetAsyncKeyState(VK_LBUTTON) & 0x8000) 
            {
                INPUT input[2];
                input[0].type = input[1].type = INPUT_MOUSE;
                input[0].mi.dx = 0;
                input[0].mi.dy = 0;
                input[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
                input[1].mi.dx = 0;
                input[1].mi.dy = 0;
                input[1].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
                SendInput(2, input, sizeof(INPUT) * 2);
            }
        }


    } while (true);
answered on Stack Overflow Jan 22, 2019 by Drake Wu

User contributions licensed under CC BY-SA 3.0