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
last_press = 0;
number_presses = 0;
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;
}
There is a simple solution, this in particular detects multiple presses and does not require alarms.
Create:
On key down:Code:last_press = 0; number_presses = 0;
MULTI_PRESS_THRESHOLD should be defined in a macro, as milliseconds. As an example, 300 would be a good value.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; }
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.In this example you would need to put this code into every key event that would use it right?
I say click the same key two times for determinate action, double tap right key for exampleIf I understand correctly..
Code:if (keyboard_check(whatever) || keyboard_check(whatever_else) { stuff }