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 


[C++] Beginners Heaven

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Drkgodz
Flash moderator
Reputation: 2

Joined: 17 Jul 2006
Posts: 2997
Location: Houston

PostPosted: Wed Mar 14, 2007 3:25 pm    Post subject: [C++] Beginners Heaven Reply with quote

First one is:
Code:

VkKeyScan('z')

Now...what could that be? Obviously it has something to do with keys. What this does is return the Virtual Keycode of the letter you put inside the ' '. This isn't useful by itself, but if you need to use something that sends keys, this is a life saver. Usually, you have to look up the Virtual Key Codes using msdn, but with this handy function, you don't need to go on MSDN. Smile
Now to use this in a piece of code:
Code:

   INPUT Input;
   ZeroMemory(&Input, sizeof(Input));
   Input.type = INPUT_KEYBOARD;
   Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
   Input.ki.wVk = VkKeyScan('z');
   SendInput(1, &Input, sizeof(INPUT));
}

What this does is send keys. It will send z only once. If you want to send it more than once, then paste that line again. If you want to change what key is sent, then change the key in the code. Rolling Eyes
Now how about making it keep on sending?
Code:

for(;;)
{
   INPUT Input;
   ZeroMemory(&Input, sizeof(Input));
   Input.type = INPUT_KEYBOARD;
   Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
   Input.ki.wVk = VkKeyScan('z');
   SendInput(1, &Input, sizeof(INPUT));

}

That will keep on sending the key z. Now don't try to make a bot for Maple Story unless you know how to hook sending keys.
If you want to send it for only a set amount...
Code:

while(x<=amount)
{
   INPUT Input;
   ZeroMemory(&Input, sizeof(Input));
   Input.type = INPUT_KEYBOARD;
   Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
   Input.ki.wVk = VkKeyScan('z');
   SendInput(1, &Input, sizeof(INPUT));
   x++;
}

Replace amount with how many times you want to send it. Remember to declare x. Like this:
Code:

int x = 0;

Another way to do the same thing?
Code:

for(int x = 0;x<amount;x++)
{
   keybd_event(VkKeyScan('z'), 0, 0, 0);
}

This is a handy loop because it declares your variable(if you want to), sets the if, and it does one function right when it starts. This is how it is like:
Code:

for(variable;the if;function that happens right away)

Think of it like this.
For = While+If
Now we can't have a bot without an Auto Clicker, now can we? Smile
Here is the code for an auto clicker.
Code:

mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP  , 0, 0, 0, 0 );

That does exactly ONE click.
To make an auto clicker:
Code:

while(0 == 0)
{
   mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
   mouse_event( MOUSEEVENTF_LEFTUP  , 0, 0, 0, 0 );
   Sleep(10);//Need this to stop crashes
}

I might add more later. Like hotkeys and such.

_________________


Last edited by Drkgodz on Thu Mar 15, 2007 11:48 am; edited 1 time in total
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Mar 14, 2007 4:02 pm    Post subject: Reply with quote

keybd_event should be replaced by SendInput Neutral

Code:

void Send_Input(BYTE vKey)
{
   INPUT Input;
   ZeroMemory(&Input, sizeof(Input));
   Input.type = INPUT_KEYBOARD;
   Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
   Input.ki.wVk = vKey;

   SendInput(1, &Input, sizeof(INPUT));
}
Back to top
View user's profile Send private message MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Wed Mar 14, 2007 4:10 pm    Post subject: Reply with quote

yes, if you go on MSDN you will see that keybd_event is deprecated and only still remains for backwards compatibility.
Back to top
View user's profile Send private message
flawedmatrix
Grandmaster Cheater
Reputation: 0

Joined: 21 Jun 2006
Posts: 819
Location: 14598622 for yourself...

PostPosted: Wed Mar 14, 2007 7:08 pm    Post subject: Reply with quote

Both keybd_event and mouse_event are superceded. For mouse event use SendInput also.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Wed Mar 14, 2007 7:20 pm    Post subject: Reply with quote

I have some comments on the tutorial.

Code:

while (0 == 0)
{
    do whatever
}


This is bad coding, you're adding a compare and additional code for a break for NOTHING. The proper way to do an infinite loop is:

Code:

for (;;)
{
    do whatever
}


This way you KNOW how execution will go, and if we progress to sometime in the future where 0 does NOT equal 0 and someone tries to take your brilliant program and compile it, it will act strange.

Secondly, Sleep does not stop crashes, if you try a loop like that, it'll take up all your computer resources, unless you have a dual core system, then it only takes up 50%, and Sleep(1) will even stop that.

...and

Code:

for(int x = 0;x<amount;x++)


poor design, you should declare x outside of the for loop and initialize it there, that way the code is compatible with the C99 standard and aren't using cpp exclusive features just because you don't know how not to.

There are also a lot of things you left unexplained in the tutorial, like why you call mouse_event again with MOUSEEVENTF_LEFTUP, and strangely enough you don't even bother to do it with keybd_event which is the proper thing to do, because if not the key is assumed to be left down until you press another.
Back to top
View user's profile Send private message
flawedmatrix
Grandmaster Cheater
Reputation: 0

Joined: 21 Jun 2006
Posts: 819
Location: 14598622 for yourself...

PostPosted: Wed Mar 14, 2007 7:39 pm    Post subject: Reply with quote

Doesn't Sleep() freeze the program momentarily? So any command you enter would be ignored...? I think its also resource wasting.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Wed Mar 14, 2007 7:57 pm    Post subject: Reply with quote

no.

Sleep is simply a polling loop that polls the kernel (which is why making your own implementation will fail) for the time until the specified milliseconds are up.
Back to top
View user's profile Send private message
flawedmatrix
Grandmaster Cheater
Reputation: 0

Joined: 21 Jun 2006
Posts: 819
Location: 14598622 for yourself...

PostPosted: Wed Mar 14, 2007 8:44 pm    Post subject: Reply with quote

appalsap wrote:
no.

Sleep is simply a polling loop that polls the kernel (which is why making your own implementation will fail) for the time until the specified milliseconds are up.


I should get into this stuff more. Normally, I program knowing what the functions do, but not how they do it.

_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Drkgodz
Flash moderator
Reputation: 2

Joined: 17 Jul 2006
Posts: 2997
Location: Houston

PostPosted: Wed Mar 14, 2007 9:49 pm    Post subject: This post has 1 review(s) Reply with quote

I said this was basics didn't I?
_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Thu Mar 15, 2007 6:07 am    Post subject: Reply with quote

If you're going to make an impression on newbies you might as well make it a good one, just because you were taught wrong does not mean you have to spread the suffering.

I'm shocked, you didn't take the feedback at all and just.. left it? Confused
Back to top
View user's profile Send private message
Drkgodz
Flash moderator
Reputation: 2

Joined: 17 Jul 2006
Posts: 2997
Location: Houston

PostPosted: Thu Mar 15, 2007 11:32 am    Post subject: Reply with quote

Ok fine. I will edit it, and replace keybd_event with SendInput.
_________________
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Thu Mar 15, 2007 7:36 pm    Post subject: Reply with quote

Using VkKeyScan() is not really needed. The VK value for the letters and numbers are the same as their ascii value. So the same value can be obtained by putting single quotes around the character. Just be sure to use capitals for the letters. For non-letters and numbers, VK_key can be used. For example, tab key is VK_TAB, F10 is VK_F10, left shift is VK_LSHIFT. All of these are defined in winuser.h which is included in windows.h.
_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Fri Mar 16, 2007 3:54 am    Post subject: Reply with quote

Code:

INPUT Input;
ZeroMemory(&Input, sizeof(Input));
Input.type = INPUT_KEYBOARD;
Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
Input.ki.wVk = VkKeyScan('z');


Should be outside the loop. Only SendInput should be in the loop.
Back to top
View user's profile Send private message MSN Messenger
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