Simple code making monitor go on and off

May 28, 2014 at 4:04am
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;

}

	
May 28, 2014 at 5:35am
What do you normally expect to happen when you feed junk to a function?
May 28, 2014 at 2:27pm
An explanation would be nice.
May 28, 2014 at 3:42pm
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).
May 28, 2014 at 3:44pm
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 May 28, 2014 at 3:53pm
May 28, 2014 at 4:24pm
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.
May 28, 2014 at 5:39pm
Alright, you guys are a big help ^_^
Topic archived. No new replies allowed.