[HELP] hold and press a key at the same time
#1

i want so when i hold CTRL (KEY_ACTION) and then press SPACE (KEY_HANDBRAKE) at the same time to call the function
but it only works in a reversed way, it works when i hold SPACE and then Press CTRL

So what i want is, call the function by holding KEY_ACTION (default left CTRL key) and pressing KEY_HANDBRAKE
(default spacebar) at the same time.

here is the code
Код:
if((newkeys & (KEY_ACTION | KEY_HANDBRAKE)) == (KEY_ACTION | KEY_HANDBRAKE) && (oldkeys & (KEY_ACTION | KEY_HANDBRAKE)) != (KEY_ACTION | KEY_HANDBRAKE))
{
     // MY FUNCITON WILL BE HERE
}
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Use the macros:

https://sampwiki.blast.hk/wiki/OnPlayer...Simplification

Код:
if (HOLDING(KEY_ACTION) && PRESSED(KEY_HANDBRAKE))
{
}
Much simpler than trying to work out all the bit manipulations.
I tried that, but its only the reverse
doesn't work with holding ctrl and pressing space
but work with holding space and pressing ctrl
idk what is the meaning of this
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
I think the problem is the confusion of terms between holding and pressing. If you just want to activate when both are pressed, check both are pressed:

Код:
if (PRESSED(KEY_ACTION | KEY_HANDBRAKE))
{
}
Still the same result
Tschh..
Reply
#4

Код:
if((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE) && (newkeys & KEY_ACTION))
This will react only if KEY_HANDBRAKE is pressed but wasn't pressed before and KEY_ACTION is already pressed.
Reply
#5

Quote:
Originally Posted by NaS
Посмотреть сообщение
Код:
if((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE) && (newkeys & KEY_ACTION))
This will react only if KEY_HANDBRAKE is pressed but wasn't pressed before and KEY_ACTION is already pressed.
I fixed it, the problem was that
another "if(KeyPressed(KEY_HANDBRAKE))" was placed before "if(KeyHeld(KEY_ACTION) && KeyPressed(KEY_HANDBRAKE))"

Thanks ****** & THANKS Nas!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)