Skip to content

to_if_held_down action triggers prematurely #4407

@gregorias

Description

@gregorias

Setting a variable in a to action and unsetting it in to_if_held_down may cause the variable to never be set for low values of to_if_held_down_threshold_milliseconds.

Reproduction

  1. Add the following complex modification:
{
    "description": "testtest",
    "manipulators": [
        {
            "from": { "key_code": "q" },
            "to": [
                {
                    "set_variable": {
                        "name": "layer-q",
                        "value": 1
                    }
                },
                {
                    "set_variable": {
                        "name": "layer-q-start",
                        "value": 1
                    }
                }
            ],
            "to_after_key_up": [
                {
                    "set_variable": {
                        "name": "layer-q",
                        "value": 0
                    }
                },
                {
                    "set_variable": {
                        "name": "layer-q-start",
                        "value": 0
                    }
                }
            ],
            "to_if_alone": [{ "key_code": "q" }],
            "to_if_held_down": [
                {
                    "set_variable": {
                        "name": "layer-q-start",
                        "value": 0
                    }
                }
            ],
            "type": "basic"
        }
    ]
}
  1. Set to_if_held_down_threshold_milliseconds to 110 ms or lower.
  2. Open Karabiner-EventViewer and the variables tab.
  3. Press and hold q.

Observed behavior

(Not 100% reliable, decrease to_if_held_down_threshold_milliseconds to increase chances.)

You’ll see that layer-q gets set to 1 but layer-q-start remains at 0.

I have recorded my view as I continuously press q:

Screen.Recording.2026-02-20.at.07.01.15.mov

Most of the time, I trigger the bug.

Expected behavior

layer-q-start flashes to 1 for the duration of to_if_held_down_threshold_milliseconds.

Notes

  • Increasing to_if_held_down_threshold_milliseconds resolves this issue.
  • This behavior breaks my hold-tap layer causing it to lose keys during fast typing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions