Windows autoclicker with a console interface I have recently started coding in c++ and have made a simple console application. When executed the program asks the user to position their cursor wherever they want continuous repeating clicks, after 7 seconds it then asks the user to set an interval for the clicks. Since I am fairly new I am wondering if there is anything I could have done better to optimise the performance of the code or any other tips and tricks I can use, much appreciated

my code is (main.cpp):

#include &lt;iostream&gt;
#include &lt;Windows.h&gt;

using namespace std;

void leftClick(double mouse_x, double mouse_y){
        INPUT input;
        input.type=INPUT_MOUSE;
        input.mi.dx=(mouse_x * 65536) / GetSystemMetrics(SM_CXSCREEN) + 1;
        input.mi.dy=(mouse_y * 65536) / GetSystemMetrics(SM_CYSCREEN) + 1;
        input.mi.dwFlags=(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE|MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP);
        input.mi.mouseData=0;
        input.mi.time=0;
        SendInput(1,&amp;input,sizeof(INPUT));
}

int main(){
    cout &lt;&lt; "Place the cursor where you want to click..." &lt;&lt; endl;
    Sleep(7000);

    POINT p;
    GetCursorPos(&amp;p);

    cout &lt;&lt; "Set the interval to click: ";

    int cinterval {0};
    cin &gt;&gt; cinterval;

    cout &lt;&lt; "Current Interval: " &lt;&lt; cinterval * 1000 &lt;&lt; endl;

    while(true){
        leftClick(p.x, p.y);
        Sleep(cinterval * 1000);
    }

     return 0;
}
Here are some suggestions you can use to improve your code.

Formatting

Insert a space before a { that starts a compound statement and does not go on a separate line; e.g., instead of int main(){, write

int main() {


or

int main()
{


Place a space after a comma and after a control word (while, etc.):         SendInput(1, &amp;input, sizeof(INPUT)) and while (true) {.

Place two spaces around the = operator.

The indentation level of the leftClick function should be reduced to 4 spaces to keep consistent with main.

Naming

In C++, functions are usually named in snake_case instead of camelCase.  This is subjective though.

Standard library usage

Please try to avoid using namespace std; because it is considered bad practice.  The contents of the C++ standard library are put in a special namespace to avoid polluting the global namespace and causing name clashes.  The std namespace is not intended for use with using directives (in general).  using namespace std; forces you to avoid standard names and invalidates the purpose of the std namespace.  See Why is “using namespace std;” considered bad practice?.

std::endl is generally inferior to \n, but it is necessary in this case because of flushing requirements.  Good.

Currently, your code isn't clear in terms of unit of time.  Is the interval intended to be in seconds, milliseconds, or microseconds?  The standard &lt;chrono&gt; library solves this problem.  And instead of Sleep, use std::this_thread::sleep_for from &lt;thread&gt;, which plays well with &lt;chrono&gt;:

using namespace std::chrono_literals;

std::cout &lt;&lt; "Place the cursor where you want to click ..." &lt;&lt; std::endl;
std::this_thread::sleep_for(7s); // NB: valid syntax!


Indicate your presumed unit of time:

cout &lt;&lt; "Set the interval to click (ms): ";

int cinterval {0};
cin &gt;&gt; cinterval;

// ...
std::this_thread::sleep_for(std::chrono::milliseconds{cinterval});