1) Name your variables; x,y is not very informative. I had to analyze the loop for a moment longer than normal. Not a big deal, but not ideal either.
bool spamBot(
string text, int x, int y)
{
HWND spamWindow = GetForegroundWindow(); //problem starts here, only keystrokes notepad help!
if(spamWindow == NULL)
return FALSE;
//Handle of notepad control
HWND edit = FindWindowEx( spamWindow, NULL, _T( "Edit" ), NULL );
if(edit == NULL)
return FALSE;
for(int z=0;
z<y;z++)
{
.....
2) You did "using namespace std;"
but still prefix things with the namespace : p Not sure if that's good/bad/either.
int main()
{
std::string text;
std::cout << "Insert Desired Text: " << endl;
getline(cin, text);
3) Use if / elseif (instead of 2 sepearate if statements; they're obviously connected)
if (start == "y")
{
cout << "5" << endl;
Sleep(1000);
cout << "4" << endl;
Sleep(1000);
cout << "3" << endl;
Sleep(1000);
cout << "2" << endl;
Sleep(1000);
cout << "1" << endl;
Sleep(1000);
spamBot(text, intervels, numOfTimes);
}
if (start == "n")
{
return 0;
}
So if the user input 'y', then obviously the 2nd if statement's body won't execute -- but it still checks the condition. It's only a couple (?) clock cycles, so not really a big deal, but it's a very easy fix, and it's common to the language, so why not.
If you use else if ( )
then once a branch of the IF has been executed, it won't check the rest of the branches.
Code:
if (start == 'y')
{
...
}
else if (start == 'n')
{
...
}
else
{
//invalid input
}
So if the user types in 'y', it will execute it's body and then leave the entire IF statement, and not check any other cases. (You only had one other case, so again, not a big deal).
4) This will probably never occur?
You're calling main() and restart() recursively (?)
void restart()
{
cout << endl;
cout << endl;
main();
willRestart = "null";
text = "null";
intervels = 0;
numOfTimes = 0;
start = "null";
}
So, before 'restart()' can return, it has to call main --> and technically main could call 'restart()' again, and so on, forever. Eventually you'd run out of stack space (ram).
I guess it's fine, as all recursive functions do that. But if there is ever a situation where a user (or users..) continuously choose to restart, eventually it will crash. Just saying : p It's not likely, but if you could re-structure the code, you might try to do so.
-optional
Code:
if (start == "y")
{
cout << "5" << endl;
Sleep(1000);
cout << "4" << endl;
Sleep(1000);
cout << "3" << endl;
Sleep(1000);
cout << "2" << endl;
Sleep(1000);
cout << "1" << endl;
Sleep(1000);
spamBot(text, intervels, numOfTimes);
}
could become
Code:
if (start == 'y')
{
for (int i = 5; i > 0; --i)
{
cout << i << endl;
Sleep(1000);
}
spamBot(text, intervels, numOfTimes);
}
5 lines, counting the braces on their own line vs. 10. Is maybe more clear the way you have it now.