the issue I'm having is that upon executing this code, it clicks, and then my monitor turns blue and says "HDMI no cable connected", and either returns back to normal after 1 second, or stays on that screen until I perform an action (click, alt etc).
Anybody with any idea on why this is happening would be appreciated.
#include "stdafx.h"
#include <Windows.h>
using namespace std;
void function() {
INPUT Input;
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(true, &Input, sizeof(Input));
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(true, &Input, sizeof(Input));
};
int main()
{
Sleep(3000);
function();
return 0;
}
Also, I'm using Visual Studio 2017 Community. This problem occurs when debugging the code, and when running the executable. There are no errors or warnings with my code.
You are not initializing most of
INPUT
fields sending some garbage and potentially triggering Undefined Behavior. You should at least fill them with zeros:You are not initializing the INPUT structure properly thus (probably) invoking undefined behavior. Initialize the structure fields to zeros using:
You can also go with an array of two elements:
followed by a:
and one call to SendInput: