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.

Dark GDK / dbKeyState WAS PRESSED instead of IS BIENG PRESSED?

Author
Message
DnB
15
Years of Service
User Offline
Joined: 28th Feb 2009
Location:
Posted: 12th May 2009 14:43
Hey everyone, I am sure people have come across this before but how would I whip up a code that would ask "WAS THE KEY PRESSED" instead of it always returning a "1" (TRUE) that a key IS BEING PRESSED. I am making a music game and I dont want it to put down a bunch of notes depending on how long someone holds the key.
I could not find any post where this was discussed. I am using dbKeyState.

THANKS IN ADVANCE FOR THE PEOPLE WHO HELP ME OUT ON THIS!! I will repay you if I can.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 12th May 2009 15:01
Set a bool value at the end of a frame, and then at the beginning of the next check this against the current frame. If they are different, and the key is down now, it has been pressed.

DnB
15
Years of Service
User Offline
Joined: 28th Feb 2009
Location:
Posted: 12th May 2009 15:11
Awesome! Thanks for the superfast response! Although you lose me with the "frame".

Could you possibly spoon feed me a little code??

Please good sir
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 12th May 2009 18:34
I use frame to refer to every run of the main loop of the game code. Hence "frames per second".
Here's a little example:


DnB
15
Years of Service
User Offline
Joined: 28th Feb 2009
Location:
Posted: 12th May 2009 19:10
AH! I do see! Yea I drew a blank when you said frame for some reason. Thanks a lot for the code though! This will definitely help me out.

Login to post a reply

Server time is: 2024-10-01 01:20:58
Your offset time is: 2024-10-01 01:20:58