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 / Trapping key up events

Author
Message
Trullion
14
Years of Service
User Offline
Joined: 1st Oct 2009
Location:
Posted: 11th Mar 2010 19:01
I am having a hard time using a key to activate something in DARK GDk/C++. For example if I want to toggle autorun on I might want to press the "R" key. Then press the "R" key again to toggle it off. While I can use the dbScanKey command to trap the "R" key being down, it loops so fast that it toggles the autorun on and off before I can release the button. ANy suggestions for trapping the key-up event? Or alternate methods?
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Mar 2010 19:50
Use a boolean variable to store the last status of the key. Example that watches the release of the Return key:



If you have several keys to watch, store their statuses in an array.
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 11th Mar 2010 20:13
you can also make it a timer, like so:



so when you press it it will only activate once unless you let go and then press again.

hi
Trullion
14
Years of Service
User Offline
Joined: 1st Oct 2009
Location:
Posted: 30th Mar 2010 21:20
I thought I had posted my final code, but it isns there so I iwll post it.

I used basically a counter that engages while a key is pressed.

Trullion
14
Years of Service
User Offline
Joined: 1st Oct 2009
Location:
Posted: 30th Mar 2010 21:23
The counter resets to 0 after the the key is released, so you can basically only toggle one thing at a time. Also it resets itself after 200 cycles which is about 2 or 3 seconds.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 31st Mar 2010 03:49 Edited at: 31st Mar 2010 04:49
Try this: Note, conceptual example...



Enjoy,

JTK

edit: Oops, that's better
edit 2: Man, where is my mind today...?
TeenCHristian
13
Years of Service
User Offline
Joined: 22nd Jun 2010
Location:
Posted: 27th Jul 2010 16:36
Sorry to be alittle off topic, but I had a question for trullion.

What code do you use trap a key? Your help is much appreciated!

Learning C++
Proud member of www.codecall.com

Login to post a reply

Server time is: 2024-04-20 03:57:31
Your offset time is: 2024-04-20 03:57:31