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 


[Tutorial]Using GetAsyncKeyState With Shift, etc. {EASY}
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sat Dec 06, 2008 5:09 pm    Post subject: Reply with quote

rapion124 wrote:
If you don't know the C++ operators, you don't deserve to be called a C++ programmer. I bet most of you don't know whether '&&' is bitwise or logical o_O


&& is logical AND
& is bitwise AND

_________________
Back to top
View user's profile Send private message Send e-mail
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sat Dec 06, 2008 7:37 pm    Post subject: Reply with quote

rapion124 wrote:
If you don't know the C++ operators, you don't deserve to be called a C++ programmer. I bet most of you don't know whether '&&' is bitwise or logical o_O

I bet many of us do, and even more don't. There are lots of operators most new C++ programmers don't know about.

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sun Dec 07, 2008 2:23 am    Post subject: Reply with quote

rapion124 wrote:
If you don't know the C++ operators, you don't deserve to be called a C++ programmer. I bet most of you don't know whether '&&' is bitwise or logical o_O


Its logical right?
and '&' is bitwise right?

edit:
kitterz allread posted...
Back to top
View user's profile Send private message
FerrisBuellerYourMyHero
Master Cheater
Reputation: 0

Joined: 14 Feb 2007
Posts: 401
Location: Inside your <kernel>

PostPosted: Mon Dec 08, 2008 11:58 am    Post subject: Reply with quote

HolyBlah wrote:
Anden100 wrote:
Code:
if (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_F1))

Try to press "F1" and then let it go again, then press "Shift", and it will use the hotkeys, you dont need to press them at the same time Wink
That's because "GetAsyncKeyState" doesn't return true or false.
@threadstarter: You should add "&& 0x8000" to the if so it will return TRUE only when both keys are down Wink .


actually you mean "& 0x8000"! as people have stated in here, single "&" is bitwise, and double "&&" is logical... same with "|" && "||" Wink

bitwise is like you would do in assembly

&:
Code:

and eax, 0x539


|:
Code:

or eax, 0x3419


And I think you know what logical is...

Anyway HolyBlah is right. I had this same problem before, where both keys did not have to be pressed simultaneously. Just so long as all the keys were pressed at some point. I overcame this issue by using the & 0x8000 like anden mentioned...

Here's an example. Say you wanted to tell the difference between a regular F1 press, && an F1 press with control[VK_CONTROL] being held down... So that you can enable a certain hack with just F1 pressed by itself, && a different hack when F1 && control are both being pressed at the same time.

So for your regular F1 press, you want to first make sure control isn't currently down, and if its not then check if F1 is down.

Code:

if(((GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0) && (GetAsyncKeyState(VK_F1) < 0))


So if control is not down AND F1 is down, then the code in the if statement will run...

you could also do it like:
Code:

if(((GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0) && (GetAsyncKeyState(VK_F1) & 0x8000))


but its shorter to just do < 0


then for the F1 press with control being held down you can probably figure that out knowing the above but its like this...

Code:

if((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_F1) < 0))


if control is down AND F1 is down, execute code...

the way the operators are is important, if the && was wrongly made bitwise & it would not work right!

_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!

Back to top
View user's profile Send private message MSN Messenger
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Dec 08, 2008 12:33 pm    Post subject: Reply with quote

if( GetAsyncKeyState(KEY) & 0x8000 )

is the same as

if( GetAsyncKeyState(KEY) < 0 )

right? (Because it returns a signed short, so when the highest bit (0x8000) is set it will be less than zero so that's the same)
If it GetAsyncKeyState would return an unsigned short it would be different.
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
Goto page Previous  1, 2
Page 2 of 2

 
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