Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to determine the press of the second key?

Author
Message
metamorpho
8
Years of Service
User Offline
Joined: 17th Oct 2016
Location: Planet Earth
Posted: 26th May 2019 17:41
The main character runs to the right and when you press the key "A" jumps. In a game with a constantly pressed key to the right (cursor arrows), it is necessary to determine the short-term pressing of the "A" key.
I am doing this check:
If GetRawKeyState (65) And GetRawKeyState (39)

but this code only responds if you hold the "A" key down a bit, and this code does not respond to a short press of the "A" key.
How can I determine the short press of the key "A"?
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 26th May 2019 18:26
if GetRawKeyState(39) and GetRawKeyPressed(65)
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th May 2019 18:30
Hi there
I think we have better here to do so ...

if (GetRawKeyState( 39 ))
if (GetRawKeyState( 65 ))
do whatever.....
endif
endif
I'm not a grumpy grandpa
metamorpho
8
Years of Service
User Offline
Joined: 17th Oct 2016
Location: Planet Earth
Posted: 28th May 2019 16:02
basicFanatic, chafari thank !!

Are there any other options ?
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 28th May 2019 23:37 Edited at: 28th May 2019 23:38


This way you can jump even without running in any direction


PSY LABS Games
Coders don't die, they just gosub without return
metamorpho
8
Years of Service
User Offline
Joined: 17th Oct 2016
Location: Planet Earth
Posted: 29th May 2019 12:30
PSY, thank !!
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 30th May 2019 03:57


Strictly speaking, this is likely how AppGameKit already implements it's Key Inputs … but essentially this is a good practise for Keyboard / Virtual Key / Controller / Mouse / etc. inputs.
The beauty of this approach though, means only ONE of these Triggers (Held / Pressed / Released) is going to be active at any given time; and we can actually quite easily extend this with an "On Demand" Timer that'll handle things such-as "How Long has this button been Held for" … so that you can have a 4th Trigger Event, such-as Push-and-Hold Triggers.

Still this is typically a "Good" approach, to handling each key' then instead of checking for Combo-States; you can simply check for the specific Trigger Event unless of course you're looking for a specific Combination; say for example for a Fighting Game where you want to check for a Quarter Circle or such.

Login to post a reply

Server time is: 2024-11-22 21:42:56
Your offset time is: 2024-11-22 21:42:56