#26464·qmk_firmware

[Bug] last_input_activity_elapsed() gives unexpected results for combo-buffered keys

Author: preconditionCreated Sep 20, 2026Updated Sep 21, 2026
Labelsbughelp wanted

Describe the Bug

Summary

For a key that's part of a combo, last_matrix_activity_time (and therefore last_input_activity_elapsed()) gets updated at the moment the key is physically pressed. Naturally, that happens before process_combo() decides whether to actually dispatch it. If the combo doesn't complete and the key is replayed via the buffer after COMBO_TERM, any keymap code that reads last_input_activity_elapsed() inside process_record_user() for that key sees only the few milliseconds since its own (delayed) replay, not the real time since the previous keystroke.

Non-combo keys don't have this problem: their process_record_user() call happens synchronously, before keyboard_task() updates the activity timer for that press.

Why this matters

Any keymap logic gated on "was the previous key pressed within N ms" (adaptive key swaps, achordion-style timing, etc.) silently stops respecting the timeout for any key that also happens to be part of a combo. The check basically always passes.

Repro

Keymap has a combo:

c
    const uint16_t PROGMEM P_T_COMBO[] = {KC_P, HOME_T, COMBO_END};
    combo_t key_combos[] = {
        [PT_MOUSE] = COMBO(P_T_COMBO, MOUSE),
    };

and, in process_record_user, an adaptive key-swap that only fires if the previous key was pressed recently:

c
    case KC_P:
        if (record->event.pressed
            && get_last_keycode() == KC_C
            && last_input_activity_elapsed() < 1500) {
            tap_code(KC_K);
            return false;
        }
        return true;

    case KC_K:
        if (record->event.pressed
            && get_last_keycode() == KC_C
            && last_input_activity_elapsed() < 1500) {
            tap_code(KC_P);
            return false;
        }
        return true;

Intent: typing "c" then "k"/"p" quickly should swap to the other of the two; typing them more than 1.5s apart should not.

Observed: the swap works correctly for KC_K. For KC_P, the swap fires every time, even after pausing several seconds between "c" and "p" because KC_P is also a member of P_T_COMBO. Its press gets buffered by the combo engine for COMBO_TERM, but the matrix-activity timestamp is already updated at the moment of the physical press, so by the time the buffered press is replayed into process_record_user, last_input_activity_elapsed() reads only the tiny replay delay (roughly the COMBO_TERM) instead of the real gap since "c" was typed. Removing KC_P from all combos fixes it.

Possible fixes

  • Don't trigger the matrix-activity timestamp for keys that process_combo() has buffered, until they're actually dispatched (or replayed).
  • At minimum, document this interaction so keymap authors relying on last_input_activity_elapsed()/last_matrix_activity_elapsed() inside process_record_user know it's unreliable for combo-member keys.

Workaround: remove the combo or track your own timer_read() per-key instead of relying on the global activity timers.

Keyboard Used

polilla

Link to product page (if applicable)

No response

Operating System

Linux

qmk doctor Output

Ψ QMK Doctor is checking your environment.
Ψ Python version: 3.14.7
Ψ CLI version: 1.2.0
Ψ QMK home: /home/username/qmk_firmware
Ψ Detected Linux (CachyOS).
⚠ Found legacy udev rules. Please run 'util/install_udev.sh' to install the latest rules
Ψ Found QMK tools distribution directory: /home/username/.local/share/qmk
Ψ Found QMK toolchains: linuxX64:baremetalARM:a55a2b0, linuxX64:baremetalAVR:a55a2b0, linuxX64:baremetalRV32:a55a2b0
Ψ Found QMK flashutils: linuxX64:636c439
Ψ Userspace enabled: False
Ψ Git branch: develop
Ψ Repo version: 0.33.13
Ψ - Latest develop: 2026-08-27 02:13:00 +0100 (4b16b5e520) -- Rework Plover HID to use Steno keycodes (#26421)
Ψ - Latest upstream/master: 2026-08-18 01:11:26 +0200 (3f26a9232a) -- Add Revolt (rev2) keyboard (#26180)
Ψ - Latest upstream/develop: 2026-09-09 21:39:53 -0700 (bf56a071d2) -- store_or_get_action - cache keycode on key press, return cached keycode on key release (#25349)
Ψ - Common ancestor with upstream/master: 2026-08-18 01:11:26 +0200 (3f26a9232a) -- Add Revolt (rev2) keyboard (#26180)
Ψ - Common ancestor with upstream/develop: 2026-08-27 02:13:00 +0100 (4b16b5e520) -- Rework Plover HID to use Steno keycodes (#26421)
Ψ CLI installed in virtualenv.
Ψ All dependencies are installed.
Ψ Found arm-none-eabi-gcc version 15.2.0
Ψ Successfully compiled using arm-none-eabi-gcc
Ψ Successfully tested arm-none-eabi-binutils using arm-none-eabi-size
Ψ Found avr-gcc version 15.2.0
Ψ Successfully compiled using avr-gcc
Ψ Successfully tested avr-binutils using avr-size
Ψ Found avrdude version 8.1-2025062
Ψ Found dfu-programmer version 1.1.0
Ψ Found dfu-util version 0.11-dev
Ψ Found diff version 3.12
Ψ Found dos2unix version 7.5.7
Ψ Found git version 2.55.0
Ψ Found make version 4.4.1
Ψ Submodules are up to date.
Ψ Submodule status:
Ψ - lib/chibios: 2026-04-04 07:15:17 +0000 --  (6170ddf92d)
Ψ - lib/chibios-contrib: 2026-02-16 12:09:51 +0100 --  (5a9ad82b)
Ψ - lib/googletest: 2025-02-07 11:04:56 -0500 --  (6910c9d9)
Ψ - lib/lufa: 2022-08-26 12:09:55 +1000 --  (549b97320)
Ψ - lib/vusb: 2022-06-13 09:18:17 +1000 --  (819dbc1)
Ψ - lib/printf: 2022-06-29 23:59:58 +0300 --  (c2e3b4e)
Ψ - lib/pico-sdk: 2025-04-20 21:24:29 +1000 --  (d0c5cac)
Ψ - lib/lvgl: 2022-04-11 04:44:53 -0600 --  (e19410f8)
Ψ QMK is ready to go, but minor problems were found

Is AutoHotKey / Karabiner installed

  • AutoHotKey (Windows)
  • Karabiner (macOS)

Other keyboard-related software installed

kanata (but it only applies to the laptop keyboard)

Additional Context

No response