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 / Here's some code for use with a Menu

Author
Message
Jash
15
Years of Service
User Offline
Joined: 12th Oct 2009
Location:
Posted: 17th Oct 2009 07:54
I had a number of problems using dbKeyState to take the user's keybord input for menus and selecting in general. The problems I had were these:
1. When the user pressed down or up, the menus would scroll WAY too fast.
2. I fixed the fast scrolling by adding dbWait and/or dbSleep in my main loop and/or after called the key functions. The problem now was that if the user pressed the key while the wait+sleep functions were in progress, the keys were ignored. Also, my animations were slowed down by this method.
3. I tried using the dbTimer command to find the amount of time since the last key press. If the time was less than 200ms or so, the key functions were ignored, thereby stopping the fast scrolling. This didn't work because quickly pressed keys were ignored, it made scrolling feel unnatural, and it made my code messy.

I found what seems to be the perfect solution to these problems. I've been helped a few times on this forum and I'd like to give back by posting an example of my code that can be copied and pasted:
keys.h


That will work for key 1. If anyone can improve it, let us know!

I make the same kind of games as any Chemisty major would.
sadyk
15
Years of Service
User Offline
Joined: 6th Sep 2009
Location: Spain-Madrid
Posted: 17th Oct 2009 16:28
dont de dbKeyState() return an int, not a bool, value? why do you put it like if it is a bool value. i mean:

it should be

doesn´t it?

sorry my english
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 17th Oct 2009 17:03 Edited at: 17th Oct 2009 17:04
dbKeyState
This command will return a value of one if the key specified by the scancode is pressed, otherwise zero will be returned. The scancode value is the raw value assigned to the key of the keyboard device and very often is ordered sequentially from the top left of the keyboard to the bottom right.

Syntax
int dbKeyState ( int iScanCode )

------------

Since 1 is equal to 'true' and 0 is equal to 'false', so it'd be the same.

if(asleep) sheep++;

Login to post a reply

Server time is: 2024-11-19 06:10:15
Your offset time is: 2024-11-19 06:10:15