pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.63k stars 836 forks source link

Add ability to pause between keystrokes arbitrarily anywhere #3807

Open momomo opened 4 months ago

momomo commented 4 months ago

Take this example:


{
        // Does not really work well
        "type": "basic",

        "from": {
            "key_code": "period",
            "modifiers": {
                "mandatory": [
                    "left_shift",
                    "left_option"
                ]
            }
        },

        "to": [

            {
                "key_code": "right_arrow",
                "modifiers": [
                    "left_option",

                    "right_control",
                    "right_shift"
                ]
            },

            // Pause here for 0.25 seconds 

            {
                "key_code": "tab",
                "modifiers": [
                    "left_command"
                ]
            },

            // Pause here for 0.25 seconds 

            {
                "key_code": "left_arrow",
                "modifiers": [
                    "left_option",

                    "right_control",
                    "right_shift"
                ]
            }

        ]
    }

The issue is that the keys are invoked way too fast after each other thus not allowing the computer to execute the intended actions fully.

Ideally we would like to pause between certain keystrokes as a program might be running that is laggy or slow.

It could be something along the lines

{
   wait: {
        time: 500
   }

}

or

{
   wait: {
        until: application is in front "abcdef" 
   }

}

you would likely have to rework how things are executed or add a whole new to_pausable logic to handle it to pull this off.

However, the need for something like this has arisen multiple times so it is a very valid usecase. Sometimes, there needs to be a delay when one keystroke or shortcut is to trigger multiple keystrokes that do things that might take certain time. We the developer is already in a messy situation utilizing karabiner so its just about enabling the workflow to improve further.

If you don't see the usecase, realize the use case is not about you.

ToeKneeFan commented 3 months ago

For now, you can emulate this with to_delayed_action (link). The delay can be configured with the basic.to_delayed_action_delay_milliseconds parameter. The documentation says "to_delayed_action posts events after 500 milliseconds from the from key is pressed", so I am not sure if it guarantees ordering (may be based on delay from from rather than last key), but well-chosen delays should essentially give you what you want.

momomo commented 3 months ago

@ToeKneeFan

No, that only works for first keystroke. I am talking about pausing between subsequent keystrokes.

If you type on a keyboard, you might type a ... wait for a menu, then enter next keystroke ... so a wait not just on the first, but even later ...

ToeKneeFan commented 3 months ago

Ah, good point. One suggestion here is to just hold down a key longer with hold_down_milliseconds (not one where holding down the key would affect the output, like a letter, but instead, for example, a modifier key). But I can see the merits of your feature request to avoid some side effects of this workaround.

hyuri commented 2 days ago

Came here to suggest this. Very needed in some cases, like when you have a sequence of shortcuts and one of them triggers opening a dialog with animation — so the next shortcut in the chain isn't activated because the animation hasn't finished yet and so the dialog isn't ready for the next action.