Detect two keys
#1

Hi, I'm trying to detect if player pressed N and H at the same time so I copied it exactly how it is in wiki, but it's not working.
This is what it looks like:

Код:
//OnPlayerKeyStateChange...
if ((newkeys & (KEY_NO | KEY_CTRL_BACK)) == (KEY_NO | KEY_CTRL_BACK) && (oldkeys & (KEY_NO | KEY_CTRL_BACK)) != (KEY_NO | KEY_CTRL_BACK))
What's wrong here?
Reply
#2

Have you tried printing the values? Print them in binary with %032b. You should be able to use the macro as well:
PHP код:
if(PRESSED(KEY_NO KEY_CTRL_BACK)) 
Reply
#3

The macro didn't work either, here are the values:
Код:
newkeys: 00000000000000100000000000000000
oldkeys: 00000000000000000000000000000000
newkeys: 00000000000000000000000000000000
oldkeys: 00000000000000100000000000000000
EDIT: I just noticed that H doesn't get detected when you first press N and then H. However when you press H first and then N it works fine. Here are the new results:
I pressed N, then H and then I realased H first and then N (realeasing H didn't get detected).
Код:
newkeys: 00000000000001000000000000000000
oldkeys: 00000000000000000000000000000000
newkeys: 00000000000000100000000000000000
oldkeys: 00000000000001000000000000000000
newkeys: 00000000000000000000000000000000
oldkeys: 00000000000000100000000000000000
Same thing as above, but when realising I first released N and then H (releasing H got detected here):
Код:
newkeys: 00000000000001000000000000000000
oldkeys: 00000000000000000000000000000000
newkeys: 00000000000000100000000000000000
oldkeys: 00000000000001000000000000000000
newkeys: 00000000000001000000000000000000
oldkeys: 00000000000000100000000000000000
newkeys: 00000000000000000000000000000000
oldkeys: 00000000000001000000000000000000
Reply
#4

Bumping this.
Reply
#5

I have interior enter/exit based on left alt and space and it is working for me:

Код:
if( PRESSED( KEY_SPRINT | KEY_WALK ) )
Reply
#6

if((newkeys & KEY_1) && (newkeys & KEY_2))

I think that should do the trick....
Reply
#7

I figured it out that the problem was not in the code, but in the keys. N and H didn't just work together. I tried two other keys and it worked.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)