View previous topic :: View next topic |
Author |
Message |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Sat Mar 06, 2010 7:43 pm Post subject: Detecting a double-tap.. |
|
|
Trying to make an interface to detect double-taps for any key, as the PSP has a limited control scheme.
Any ideas as far as it could be done?
I was thinking about modifying this struct:
Code: | typedef struct
{
int down[2]; // key nums holding it down
int state; // low bit is down state
} kbutton_t; |
to have a time value as well, that would be set to like time + .1 when the initial keypress is detected, then if it hasn't expired by the time the second keypress is detected, perform an alternate binding?
Is there a better way? I'm sure you people that have been modding Quake for years could think of a better way.
EDIT: I also have no clue if this is used for button presses or an on-screen-keyboard. |
|
Back to top |
|
 |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Sun Mar 07, 2010 7:14 pm Post subject: |
|
|
Got it working
If anybody wants it for one of their PSP projects, swing by me.. |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Mon Mar 08, 2010 1:17 am Post subject: |
|
|
I'd like to see the code.
How well does it work if you just single tap? _________________ Tomorrow Never Dies. I feel this Tomorrow knocking on the door ... |
|
Back to top |
|
 |
avirox
Joined: 16 Aug 2006 Posts: 109
|
Posted: Mon Mar 08, 2010 2:31 am Post subject: |
|
|
i can think of an easy way to do this in CSQC, but i am also interested in seeing how you did it in ssqc.. |
|
Back to top |
|
 |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Mon Mar 08, 2010 3:03 am Post subject: |
|
|
It's in the engine programming subforum for a reason, Avirox =O
I added the commands binddt and unbinddt and essentially copied over a bunch of the code in key.c with minor alterations to suit the double-tap array of commands assigned to keys. Then I simply had a global variable for the last pressed key and the time it was pressed, compared, and if it was within .3 "time" ago (I have no clue at the scale which Quake does time so I'll refer to it as "time" instead of seconds), I Cbuf_Addtext'd the command that the key was bound to.
For instance, in my game, I want the character to sprint when he double tapped triangle, this is what the config reads as:
Code: |
bind "TRIANGLE" "+forward"
binddt "TRIANGLE" "+forward; qcf A_Sprint;"
|
Works perfectly fine. When you single tap, it just does the normal walk forward. |
|
Back to top |
|
 |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Mon Mar 08, 2010 8:37 pm Post subject: |
|
|
Possibly another useful related idea, the idea of holding the button down for more than a second or two has an alternate function.
One possible example, alter jump so the jump occurs on key release but if the button is held more than a couple of seconds it is a forward lunge attack that knocks enemies out of the way.
Nice idea downsider on thinking how to reuse existing controls. _________________ Tomorrow Never Dies. I feel this Tomorrow knocking on the door ... |
|
Back to top |
|
 |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Mon Mar 08, 2010 10:13 pm Post subject: |
|
|
Yeah but that's quite a bit harder to implement.. Now you'd need a function calling every single frame to compare how long since the keydown event. |
|
Back to top |
|
 |
avirox
Joined: 16 Aug 2006 Posts: 109
|
Posted: Tue Mar 09, 2010 2:37 pm Post subject: |
|
|
.. which is why i asked how you were doing it in ssqc, thinking that you may have implemented some extension to read client key inputs. That's how I would do it, sans CSQC, anyways.. |
|
Back to top |
|
 |
Irritant
Joined: 19 May 2008 Posts: 115 Location: Maryland
|
|
Back to top |
|
 |
|