SA-MP Forums Archive
Detect two keys - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Detect two keys (/showthread.php?tid=633520)



Detect two keys - GoldenLion - 02.05.2017

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?


Re: Detect two keys - Vince - 02.05.2017

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)) 



Re: Detect two keys - GoldenLion - 03.05.2017

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



Re: Detect two keys - GoldenLion - 04.05.2017

Bumping this.


Re: Detect two keys - raydx - 04.05.2017

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

Код:
if( PRESSED( KEY_SPRINT | KEY_WALK ) )



Re: Detect two keys - DRIFT_HUNTER - 04.05.2017

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

I think that should do the trick....


Re: Detect two keys - GoldenLion - 04.05.2017

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.