• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Double keyboard press

S

srchaos

Guest
Hi there. So, anyone knows how to create a double keyboard check, for the same key. For example double key press vk_right or vk_left, this to do determinate action. Thanks for read :)
 

obscene

Member
If I understand correctly..

Code:
if (keyboard_check(whatever) || keyboard_check(whatever_else)
  {
  stuff
  }
 
M

Mishtiff

Guest
I believe he is looking for something more along the lines of "if i press 'a' twice, my character performs a roll to the left".

For this, I believe you can use an alarm. if the player presses and releases the left key, set an alarm for a period of time to check for it again. if the character performs the action again, do your ability. Hopefully that helps.
 
D

dj_midknight

Guest
Is there a way to grab keypresses and store then into a queue outside of the normal step sequencing? Like an independent thread that runs non stop?
 
S

Schyler

Guest
There is a simple solution, this in particular detects multiple presses and does not require alarms.

Create:
Code:
last_press = 0;
number_presses = 0;
On key down:
Code:
if (current_time - last_press < MULTI_PRESS_THRESHOLD) {
    number_presses++;
} else {
    number_presses = 1;
}

last_press = current_time;

switch (number_presses) {
    case 2: /* barrel roll */ break;
    case 3: /* rolling pounce */ break;
    default: break;
}
MULTI_PRESS_THRESHOLD should be defined in a macro, as milliseconds. As an example, 300 would be a good value.
 
D

dj_midknight

Guest
There is a simple solution, this in particular detects multiple presses and does not require alarms.

Create:
Code:
last_press = 0;
number_presses = 0;
On key down:
Code:
if (current_time - last_press < MULTI_PRESS_THRESHOLD) {
    number_presses++;
} else {
    number_presses = 1;
}

last_press = current_time;

switch (number_presses) {
    case 2: /* barrel roll */ break;
    case 3: /* rolling pounce */ break;
    default: break;
}
MULTI_PRESS_THRESHOLD should be defined in a macro, as milliseconds. As an example, 300 would be a good value.

In this example you would need to put this code into every key event that would use it right?
 
S

Schyler

Guest
In this example you would need to put this code into every key event that would use it right?
Yes, and you would need to define a separate set of variables to track the number of presses and last press time for each individual key that requires this kind of behavior.
 
S

srchaos

Guest
If I understand correctly..

Code:
if (keyboard_check(whatever) || keyboard_check(whatever_else)
  {
  stuff
  }
I say click the same key two times for determinate action, double tap right key for example
 
Top