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 <iostream>
#include <Windows.h>
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,&input,sizeof(INPUT));
}
int main(){
cout << "Place the cursor where you want to click..." << endl;
Sleep(7000);
POINT p;
GetCursorPos(&p);
cout << "Set the interval to click: ";
int cinterval {0};
cin >> cinterval;
cout << "Current Interval: " << cinterval * 1000 << endl;
while(true){
leftClick(p.x, p.y);
Sleep(cinterval * 1000);
}
return 0;
}