| View previous topic :: View next topic |
| Author |
Message |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Dec 06, 2008 5:09 pm Post subject: |
|
|
| 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 |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sat Dec 06, 2008 7:37 pm Post subject: |
|
|
| 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 |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Sun Dec 07, 2008 2:23 am Post subject: |
|
|
| 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 |
|
 |
FerrisBuellerYourMyHero Master Cheater
Reputation: 0
Joined: 14 Feb 2007 Posts: 401 Location: Inside your <kernel>
|
Posted: Mon Dec 08, 2008 11:58 am Post subject: |
|
|
| 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  | 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 . |
actually you mean "& 0x8000"! as people have stated in here, single "&" is bitwise, and double "&&" is logical... same with "|" && "||"
bitwise is like you would do in assembly
&:
|:
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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon Dec 08, 2008 12:33 pm Post subject: |
|
|
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 |
|
 |
|