 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Smr How do I cheat?
Reputation: 0
Joined: 02 Aug 2007 Posts: 7
|
Posted: Thu Aug 02, 2007 2:34 pm Post subject: Useful c++ functions |
|
|
I wrote 4 functions that people might want to use for their C++ programs.
Save the following code into a C++ header, and call it whatever.h (anything that ends in .h), then include it in your C++ sources whenever you want to use these functions
Code:
#define WIN32_LEAN_AND_MEAN // Exclude rarely used stuff from windows.h
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <windows.h>
#include <string>
#pragma message( "Remember to call seedrand() in your main() or WinMain() function! ")
using namespace std;
void seedrand() // Seed random number generator to the current system time
{
srand((unsigned)time(NULL));
}
int random(int range) // return random number within specified range
{
range = abs(range);
// if range is negative convert it to positive
return(rand()%range);
}
void movemousesmooth(int x, int y) // Stimulate humanlike mouse movement like MoveMouseSmooth in SCAR
{
for(int i = 0; i < x && i < y; i++)
{
mouse_event(MOUSEEVENTF_MOVE,(x-(x-1)),(y-(y-1)),NULL,NULL);
// if you stare at that long enough you might understand it...
Sleep(rand()%2);
// pause random milliseconds from 0-2 to make it seem humanlike
}
}
void sendkeys(string keys) // Stimulates typing a string of keys and pressing "Enter"
{
for(int i = 0; i < keys.size(); i++)
{
keybd_event(VkKeyScan(keys.at(i)),NULL,NULL,NULL);
//if its not working properly then uncomment the next line
//keybd_event(VkKeyScan(keys.at(i)),NULL,KEYEVENTF_KEYUP,NULL);
}
keybd_event(VK_RETURN,NULL,NULL,NULL);
// send the "enter" key at the end of the string
}
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Thu Aug 02, 2007 6:03 pm Post subject: |
|
|
A few things to fix:
1. SendInput, not keybd_event/mouse_event.
2. If you make a random function that specifies range, don't use (rand()%2). Use your function. (If you don't it makes it seem like you think it is useless, which is what other people will probably think.)
3. The first two functions seem superfluous. It is almost quicker to type the code in the function out every time. (Like (rand()%2) > random(2);)
4. For SendKeys, make the input value a char array and not string. You can get rid of a whole header file this way, and it is more common to see people use a char array.
5. Finally, in SendKeys, you should parse the input for escape sequences (like '\n') so they can hit enter when they want, not after the input.
|
|
| Back to top |
|
 |
BoRed Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Apr 2007 Posts: 1176 Location: ╞|ous█
|
Posted: Thu Aug 02, 2007 6:42 pm Post subject: |
|
|
Its mostly good just a few flaws =\
_________________
I got my old name back.......=)
Working on making website for stealth trainers (almonst done just having technical troubles)
Stealth forums will be down for 8 days or more starting august 2 saturday. |
|
| Back to top |
|
 |
the_human_revised How do I cheat?
Reputation: 0
Joined: 31 May 2007 Posts: 2
|
Posted: Sun Aug 05, 2007 9:27 pm Post subject: |
|
|
| There seems to be a few bugs, but thanks anyways.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|