Time Functions

Use these calls for cooldowns, time windows, performance checks, and combo delays.

Quick Reference

Function Returns Meaning
system_time() int Current runtime time in milliseconds
elapsed_time() int Milliseconds since the previous main iteration
output_time() int Milliseconds since the previous output update
wait(ms) int Pause the current combo step

get_rtime() is a compatibility alias for elapsed_time().

Measuring a Time Window

Store a system_time() value and subtract it from the current value. elapsed_time() does not accept a timestamp argument.

gpc
int last_action = 0;

main {
    if (event_active(BUTTON_12) && system_time() - last_action >= 1000) {
        combo_run(Action);
        last_action = system_time();
    }
}

combo Action {
    set_val(BUTTON_15, 100);
    wait(60);
    set_val(BUTTON_15, 0);
}

Double Tap

Track the first press before using time_release() for the gap between taps. This prevents an early first press from being mistaken for a double tap:

gpc
bool waiting_for_second_tap = FALSE;

main {
    if (event_active(BUTTON_15)) {
        if (waiting_for_second_tap && time_release(BUTTON_15) <= 280) {
            combo_run(DoubleTapAction);
            waiting_for_second_tap = FALSE;
        } else {
            waiting_for_second_tap = TRUE;
        }
    }
}

combo DoubleTapAction {
    set_val(BUTTON_15, 100);
    wait(60);
    set_val(BUTTON_15, 0);
    wait(100);
}

Long Press

gpc
main {
    if (check_active(BUTTON_1, 1000)) {
        printf("Long press detected");
    }
}

Combo Delays

wait() is valid only inside a combo block. Values set before it remain active for the wait period.

gpc
combo TapButton {
    set_val(BUTTON_16, 100);
    wait(70);
    set_val(BUTTON_16, 0);
    wait(70);
}

Notes

  • Use system_time() - saved_time for cooldowns and periodic actions.
  • Use elapsed_time() when the duration of the last main-loop interval itself matters.
  • Use time_active(), time_release(), check_active(), and check_release() for input transitions.