Automatic mouse clicks make the screen blank

Hi guys, I'm working on writing a program that will do a few clicks for me in a loop. I created a structure and set it to enter INPUT_MOUSE for replicating clicks and using SendInput () to send information. everything compiles correctly and can be called a "working" program, but I came across a rather funny breakdown. I wrote a program on my laptop (Windows Vista), tried it, and it worked fine. When I rewrote the same exact code and used it on my desktop (Windows 7), when I run the program, my screen will go black as soon as I start the automation part, as it happens when it goes to sleep . the program will run in the background just fine, but its kind of pain that automater blacks my screen. any idea what is going on here? If necessary, I can display the code. Thanks in advance.

on request I add my code

enter code here #include "stdafx.h" #include <windows.h> #include <iostream> #include <string> #include <time.h> using namespace std; void clicky(int x, int y) { // 5 sec wait clock_t run; run = clock()+5*CLOCKS_PER_SEC; while (clock() < run) {} //plug in cursor coords and click down and up SetCursorPos(x,y); INPUT mouse; mouse.type = INPUT_MOUSE; mouse.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; SendInput(1,&mouse,sizeof(INPUT)); mouse.type = INPUT_MOUSE; mouse.mi.dwFlags= MOUSEEVENTF_LEFTUP; SendInput(1,&mouse,sizeof(INPUT)); } void main() { int coords=0; string h; //find out how many clicks are needed cout << "How many clicks will you need?"; cin >> coords; //extra getline here without it when return is hit //from entering the click amount it would also enter //a cursor coordinate getline(cin,h); POINT p[21]; for (int count = 1;count<=coords;count++) { cout << "Place mouse cursor where you want a click and press return"<<endl; //each time return is hit the cursor coordinates //will be stored in the corresponding spot in // the p array string key = "r"; getline(cin,key); GetCursorPos(&p[count]); break; } string go; cout << "Hit Return to initialize your click loop"; getline(cin,go); while (true) //infinite loop cycling through the users //cursor coordinates and clicking { for(int click=1;click<=coords;click++) { int x = p[click].x; int y = p[click].y; clicky(x,y); } } } 
+4
source share
1 answer

Try initializing the INPUT structure to all zeros before calling SendInput() , for example

 INPUT i; ZeroMemory(&i, sizeof(i)); 

Also, make sure that the coordinates you specify are not too large.

I had a screen blank (in fact, the screen saver is clogged) when you do one of these two wrong ones.

+4
source

Source: https://habr.com/ru/post/1344812/


All Articles