A Simple Function

Posts 113 of 13 · Page 1 of 1
A Simple Function
See this
[Highlight=C++]
int left_click()

{
int delay = 1;
start:
INPUT Input={0};

Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;

::SendInput(1,&Input,sizeof(INPUT));




::ZeroMemory(&Input,sizeof(INPUT));

Input.type = INPUT_MOUSE;

Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;

::SendInput(1,&Input,sizeof(INPUT));
Sleep(1000*delay);

goto start;

}
[/HIGHLIGHT]
A put that function into a program(Win32 GUI based) And when I execute the function my program get Not Responding.But the progra still cliking just dont respond anymore. :X
Have something wrong with it?
Sleep stops the whole program. Execute that function in a new thread.

Edit: WHY GOTO WHY ITS EVUL D:
Interesting, never used that before
^ lolwut ? You never used a timer before ? Noob
I will try using a timer, thanks guys if it works I Tell you guys .And @Hassan you can close other thread the Minimize to tray I solved it.
Guys I tried using timer but really dont worked the program execute the function in less than 1 second or dont execute if I change something, so can someone post a example
I'm still confused on why the original code didn't work. That Sleep call should stop the program for only one second if I'm reading it right

1000 * delay(1) = 1000ms = 1 second.
Quote Originally Posted by Swampgrass View Post
I'm still confused on why the original code didn't work. That Sleep call should stop the program for only one second if I'm reading it right

1000 * delay(1) = 1000ms = 1 second.
1 second, then one second again, then another second = stopped whole time.
Nico is right it stop the program all the time, but I dont find anyway to make this work I think im just gonna give up, I dont have a good idead for program and this sucks for real just have a nice GUI so...If someone agree Close thread
Code:
#include "stdafx.h
#include <iostream>
#include <windows.h>
#include <string>
#include <ctime>

using namespace std;

int main()
{
system("color 3b"); //Changes the color of the screen.

int x;
int y;
int sleeptime;
int clickamount;

cout << "Text \n"; //Displays text.
cout << endl << endl; //Creates (x2) (enter's) two new lines.
cout << "Text" << endl << "Same credits as last time." << endl << endl;
cout << "X Cord: ";
cin >> x; //Gets information for int x.
cout << "Y Cord: ";
cin >> y;
cout << "How many times to click: ";
cin >> clickamount;
cout << "Please (:P )enter (Seconds) in time between clicks: ";
cin >> sleeptime;
cout << "X: ";
cout << x;
cout << " Y: ";
cout << y;
cout << " Sleep: ";
cout << sleeptime;
cout << " Clicks: ";
cout << clickamount;

for(int i = 0; i<clickamount; i++){ //Loop saying this int i is at the value 0. If it is < the clickamount varible than go to cin.get, else add 1 to int i and redo.
Sleep(sleeptime * 1000); //Sleep for the sleeptime and * by 1000 so it is in seconds.
SetCursorPos(x,y); //Put the mouse at the cordinates
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); //Left mouse button down
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); //Left mouse button up
keybd_event(VK_F12,0x7B,0 , 0); // F12 Press
keybd_event(VK_F12,0x9d,KEYEVENTF_KEYUP,0); // F12 Release


if(GetAsyncKeyState(VK_ESCAPE)){ //If button Escape is pressed than it will do.
exit(0); // EXIT THE PROGRAM
}
}
cout << endl;
cout << "Program is finished..." << endl;
cout << "Program shutting down in 5 minutes.";
Sleep(300 * 1000); //Makes the program sleep for 5 minutes.
exit(0);
cin.get(); //Keeps the information on the screen.
cin.get();
return 0;
}
Look at this itmay solve Your problem
It dont help me anyway, you used Sleep and Sleep is my problem, how it will help me? Read the post first man D:.
Posts 113 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?