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.

DarkBASIC Professional Discussion / Key pressed twice?

Author
Message
Aarbear
15
Years of Service
User Offline
Joined: 29th Apr 2011
Location: New York
Posted: 24th May 2011 00:22
Hi, how do you check if a key was pressed twice? or 3 times even?
I tried


It doesn't work, because when you press up once, it just activates both if statements and the end product is just "pressed twice".
Any help would be appreciated.

Thanks for reading,
~Aaron

Str8^
Teh Stone
16
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 24th May 2011 00:29
Few Steps

Check If it has Been pressed

Start Timer when button has been released

Check if button has been pressed again

Work out how long has elasped since the first press and wether that was short enough time for a double click and if not the start process again



Ive never tried this before prob not best way but atleast something to think about
Link102
21
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 24th May 2011 00:34 Edited at: 24th May 2011 01:39
You can interpret your question as 2 things;

- either count the number of times a key has been pressed
- or check for a double press.

keycounter:


check for doublepress:


Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 24th May 2011 00:36 Edited at: 24th May 2011 00:41
Not at my computer so I can't do any testing and I'm going to keep this short.

@the stone, I dont think you need to use anything relating to time for this.

@aarbear try this, I haven't been able to test it though. This will work with the upkey, you can make it work with any just change which key it has to detect for



A clever person solves a problem, a wise person avoids it - Albert Einstein
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 24th May 2011 01:04 Edited at: 24th May 2011 01:06
Yes you need time, otherwise how the heck would you check for a quick, or custom rapid double click? You don't check if a key gets pressed twice during a whole game, but during about a half sec.

Of course you can measure it in loops as well, but if the speed isn't the same as on the development machine, it can result in not being able to perform a double click/press.

Your code... two IF's built into each other... for the same condition... that was a bit low. You shouldn't share anything like that on a public forum, you are just gonna make a fool of yourself.

Just rushed together but i guess will do the job:



-In.Dev.X: A unique heavy story based shoot'em ~25%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Aarbear
15
Years of Service
User Offline
Joined: 29th Apr 2011
Location: New York
Posted: 24th May 2011 02:11
Hi Hodgey, thank you for your example. Don't worry about testing it, it works great.

Quel, I guess it all depends on your needs. Thank you for your code snippet, but I don't need a timer. As far as my IF statements go, I forgot to add that I tried adding a counting variable, it just wasn't working the way I was hoping. Also, you should work on your English, it's not always very clear. Here is a website for you http://www.englishforums.com/. Hopefully they don't ridicule you for asking for help with a language you aren't very good with yet.

Best wishes,
~Aaron

Str8^
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 24th May 2011 07:54 Edited at: 24th May 2011 11:20
Quote: "Hi Hodgey, thank you for your example. Don't worry about testing it, it works great."

You're welcome

@ Quel, this forum is supposed to be about helping people with a positive manner. The last thing people trying to learn DBPro need is someone who insults their attempt at something and tells them that they have just publically humiliated themselves. In my eyes, Aarbear asked a very logical question which can be difficult for people to grasp the concept of. Although his code may seem unlogical he did atleast have a go at solving the problem himself. I suggest you re-read your post and then read section 3.11 of the AUP.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th May 2011 11:02
Quote: "Quel, I guess it all depends on your needs. Thank you for your code snippet, but I don't need a timer. As far as my IF statements go, I forgot to add that I tried adding a counting variable, it just wasn't working the way I was hoping. Also, you should work on your English, it's not always very clear. Here is a website for you http://www.englishforums.com/. Hopefully they don't ridicule you for asking for help with a language you aren't very good with yet."

someone's angry xD
Don't feed the troll!

not that I'm saying quel is a troll, it just seems like he agitates people on purpose


To be honest, saying:

does indicate a lack of problem-solving knowledge. Still, you don't learn problem-solving by getting called a fool!


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 26th May 2011 15:51
I remember an old saying, it went something like...

Quote: " We are all stupid at something, Until we ask the stupid question."


So calling someone a fool (and indirectly you were) is just proving they got wiser. if not more informed.

I think i made my point here.

and yeah I agree with the need for time checking here as you could press a key and and press it again half an hour later and it will count as a double press regardless of how distant the press occurred, however if you can measure the ms between each pres you will be able to register a double press, so yes time is important here.

Login to post a reply

Server time is: 2026-07-10 19:47:35
Your offset time is: 2026-07-10 19:47:35