-1

I need to figure out how to send more left clicks, when I click.

Ive tried lots of beginner things, since I'm a beginner, but can't seem to figure it out without completely skidding something else.

int main() {

    bool click = false;

    while (1) {
        if (GetAsyncKeyState(VK_LBUTTON))
        {
            click = true;
        }
        if (GetAsyncKeyState(VK_LBUTTON));
        {
            click = false;
        }
        if (click == true)
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

I expect it to click 4 times when I click once, but it doesn't seem to work

user4581301
  • 33,082
  • 7
  • 33
  • 54
Bloopdog
  • 21
  • 2
  • 1
    Seems like click is set true and then immediately set false. I'd expect mouse_event never to be called. As an aside, the correct test is `GetAsyncKeyState(VK_LBUTTON) < 0`. – David Heffernan Sep 27 '19 at 19:10

1 Answers1

0

Note :This mouse_event function has been superseded. Use SendInput instead.

The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput.

Modified code:

#include <Windows.h>

int main()
{
    bool click = false;

    while (1)
    {
        if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
        {
            click = true;
        }
        if (click == true)
        {
            INPUT buffer[8];
            memset(buffer, 0, sizeof(INPUT) * 8);
            for (int i = 0; i < 7; i++)
            {
                buffer[i].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
                i++;
                buffer[i].mi.dwFlags = MOUSEEVENTF_LEFTUP;
            }
            SendInput(8, buffer, sizeof(INPUT));

            click = false;
        }

    }    
    return 0;
}

Put the key down and key up events into an array of length 2 and send them as a combination.

Set the value of ki.dwFlags to control up and down states of the key.

Because you expect it to click 4 times when click once.So you need 4 sets of such combinations.

More details, please refer this case.

Strive Sun
  • 5,988
  • 1
  • 9
  • 26