Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Useful c++ functions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Smr
How do I cheat?
Reputation: 0

Joined: 02 Aug 2007
Posts: 7

PostPosted: Thu Aug 02, 2007 2:34 pm    Post subject: Useful c++ functions Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Aug 02, 2007 6:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
BoRed
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Apr 2007
Posts: 1176
Location: ╞|ous█

PostPosted: Thu Aug 02, 2007 6:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
the_human_revised
How do I cheat?
Reputation: 0

Joined: 31 May 2007
Posts: 2

PostPosted: Sun Aug 05, 2007 9:27 pm    Post subject: Reply with quote

There seems to be a few bugs, but thanks anyways.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites