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 / key down, key up, key hold, key repeat?

Author
Message
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 19th Dec 2007 23:37
I heard there is a function in DirectInput that detects is a key is held (pressed and unreleased), key press and whether the key is "up" (unpressed) or "down" (pressed).

Do you know how i can use dbKeyState() to detect if a key is pressed and held?

dbPrint ( "Sig" );
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 19th Dec 2007 23:45
Yes Dark Basic has built in support for this:
dbUpKey()
dbDownKey()
dbLeftKey()
dbRightKey()

If you need other keys use dbScanCode(), like such:


Hope that helps!
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 20th Dec 2007 00:03 Edited at: 20th Dec 2007 00:04
Thx for your help, but I already know how to do that.

What I meant was: say we have a key... F1 for example. We press and hold F1- a certain function should start. Just pressing F1 should do a function, and holding F1 should do something else.

Any help?

EDIT: to make it clearer: we press and keep pressed F1.

dbPrint ( "Sig" );
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 20th Dec 2007 00:42
Ohh my apologies...
As far as I know, I'm not exactly sure how you would do this. I remember in DirectX you could get a keystate such as if it was pressed, held down, or released; but I haven't seen anything like that in Dark GDK. Maybe use dbTimer() with dbScanCode()?
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 20th Dec 2007 00:46
OH... DUH!

Thanks! I studied that but I forgot about it... lol

dbPrint ( "Sig" );
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 20th Dec 2007 03:43
It's okay, happy to help
Lion Jin
18
Years of Service
User Offline
Joined: 24th Sep 2006
Location:
Posted: 20th Dec 2007 04:42 Edited at: 20th Dec 2007 04:57
This is my way.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 20th Dec 2007 05:12
Also - there is a cool DBPro Code Snip - that has timer based Key's - and mroe - like Toggle and a few others - Where it won't even register a key (if you have it on a timer) until its "Ready Again"

In My GDK now - I have a timer Class - that has both stuff for adding "Timed Triggers" as well as stuff geared for the keyboard scenario I just mentioned above - like the "Controlled KeyRepeat" method - fast - slow - its up to you etc. The Nice thing about the Toggle Thing in that dbpro snip - is I think it uses some logic to prevent "Machine gun Toggle switches" Like it registers when you click it but you can't toggle again until after you let go of that key.

If I were you - I'd just look at what you can find - see if you learn something you didn't know - get an idea or whatever - then work out your own "Global" way of handling these common things You'll need and just add it to your aresenal

dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 20th Dec 2007 22:17
@Lion Jin: Thanks! I'll add it to my game.
@Jason: You're right, the only way to learn is to practice. But I didn't want to waste too much time on this simple Hold/Press issue (I'm not very good at handling input) so I made a topic.
@Crimson: I made my key hold function... But it was too long and unstable lol. Thx for your help though.

Thanks for your help everybody!
~Problem solved~

dbPrint ( "Sig" );

Login to post a reply

Server time is: 2024-10-08 18:17:54
Your offset time is: 2024-10-08 18:17:54