void leftClick(){
INPUT input[2];
input[0].type = INPUT_MOUSE;
input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
input[1].type = INPUT_MOUSE;
input[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(2, input, sizeof(INPUT));
cout<<"click down\n";
cout<<"click up\n\n";
/*
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
*/
}
ReadProcessMemory(process, (void*)address, &value, sizeof(value), 0);
if (value == 1){
if (clock() - click_time >= 500){
cout<<"click time = "<< click_time <<endl;
cout<<clock() - click_time <<endl;
leftClick();
click_time = clock();
}
}
This gives an output of
click time = 0
57209
click down
click up
click time = 57222
501
click down
click up
click time = 57738
500
click down
click up
As you can see, the clicks should be happening, but this doesn't send any clicks. It only actually clicks if I take out all the clock stuff. Same thing happens if I use mouse_event instead of SendInput.
edit: I changed SendInput up there, didn't change any behavior. The commented mouse_events gives the same behavior as well
edit: It seems I can't make a minimal reproducible example. Without ReadProcessMemory, it works fine with a delay, it only doesn't send clicks with a delay while reading the process. Looking in to issues with combining ReadProcessMemory with any sort of delayed input.