Simple code making monitor go on and off

This is an auto clicker I made but for some weird reason it makes my monitor go on and off.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <Windows.h>

using namespace std;



int main()
{

	INPUT mouse;
	mouse.type = INPUT_MOUSE;
	mouse.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;


	Sleep(5000);
while(1)
{
	 
	 SendInput(1,&mouse,sizeof(mouse));
	 Sleep(600);
}






cout << endl << endl;
system("PAUSE");
return 0;

}

	
What do you normally expect to happen when you feed junk to a function?
An explanation would be nice.
What do you think mouse.mi.dx and mouse.mi.dy equals to?
and what mouse.mi.mouseData and time equals to?

Currently it is junk. That means your mouse can suddenly jump everywhere (and click everywhere), send some random data to the system and doing strange things with time (I do not know what it si supposed to do).
An explanation would be nice.


That was an explanation in the form of a question: You're feeding junk to a function which expects you to feed it non-junk. http://en.wikipedia.org/wiki/Garbage_in,_garbage_out

Why don't you visit:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx
and take careful note of which values must be supplied and what they should be.
Last edited on
As for why this happens, WinAPI is written to target the C language as opposed to C++ which you are probably more used to. So the objects it provides do not have constructors which is why any data members that are not specifically initialized are in an undefined state.
Alright, you guys are a big help ^_^
Topic archived. No new replies allowed.