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.










share|improve this question

























  • Never mind hooking this up to input, your call to SendInput is no good and won't work on its own. Debug code by making sure the constituent parts work. Do that first.

    – David Heffernan
    Jan 19 at 13:33
















-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.










share|improve this question

























  • Never mind hooking this up to input, your call to SendInput is no good and won't work on its own. Debug code by making sure the constituent parts work. Do that first.

    – David Heffernan
    Jan 19 at 13:33














-2












-2








-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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 9:32









πάντα ῥεῖ

72.6k974140




72.6k974140










asked Jan 19 at 9:30









Taco GamezTaco Gamez

1




1













  • Never mind hooking this up to input, your call to SendInput is no good and won't work on its own. Debug code by making sure the constituent parts work. Do that first.

    – David Heffernan
    Jan 19 at 13:33



















  • Never mind hooking this up to input, your call to SendInput is no good and won't work on its own. Debug code by making sure the constituent parts work. Do that first.

    – David Heffernan
    Jan 19 at 13:33

















Never mind hooking this up to input, your call to SendInput is no good and won't work on its own. Debug code by making sure the constituent parts work. Do that first.

– David Heffernan
Jan 19 at 13:33





Never mind hooking this up to input, your call to SendInput is no good and won't work on its own. Debug code by making sure the constituent parts work. Do that first.

– David Heffernan
Jan 19 at 13:33












1 Answer
1






active

oldest

votes


















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);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265726%2floop-repeated-do-statement-with-mouse-left-button-variable-click-hold%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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);





    share|improve this 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);





      share|improve this answer


























        0












        0








        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);





        share|improve this answer













        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);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 22 at 2:57









        Drake Wu - MSFTDrake Wu - MSFT

        2425




        2425






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265726%2floop-repeated-do-statement-with-mouse-left-button-variable-click-hold%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre