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.79k stars 838 forks source link

Configurable overlap/rollover thresold eg for using spacebar as spacebar (alone) or left_control (held) #1207

Closed kbdluv closed 6 years ago

kbdluv commented 6 years ago

Opening an issue for this comment here as I face the same problem:

The implementation of to_if_alone works great as stated, but actually doesn't handle my own use case. I'm trying to map spacebar to left_command when paired with other keys, and to use it as a normal spacebar when alone. I found that even after mapping w/ to_if_alone, the main issue is that spacebar is used very often. Because of this, it's pretty common to accidentally hit another character while the space key is still pressed, especially when typing quickly.

Ideally, I could set some arbitrary [overlap/rollover] millisecond threshold. If spacebar is only held for less than that threshold, then it will always be treated as a spacebar press (Even if I press another key during that initial spacebar press). However, if I hold spacebar for more than that threshold, it will be treated as left_command[_control/etc]. If anyone's done something like that in a fork, let me know!

One proposed solution to this issue is #877, which solves the case for when the held spacebar is released after the key that is pressed with it, and I'm sure the feature has additional good uses.

I'm opening this as a separate issue because the overlap/rollover threshold would also solve the case for when the held spacebar is released before the key that is pressed with it. The order of the keydowns in that case would not be relevant.

rubas commented 6 years ago

Same boat as I want to map some modifier to the homerow. Rollover is a big issue and makes it not usable at the moment. :(

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

elasticdog commented 5 years ago

@jonathankau @kbdluv @rubas I think I came up with a working solution (on Karabiner-Elements v12.2.0) to prevent accidental modifier hits via a delay:

{
    "description": "spacebar -> left_command (spacebar if pressed alone)",
    "manipulators": [
        {
            "from": {
                "key_code": "spacebar",
                "modifiers": {
                    "optional": ["any"]
                }
            },
            "parameters": {
                "basic.to_delayed_action_delay_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to_delayed_action": {
                "to_if_canceled": [
                    {
                        "key_code": "spacebar"
                    }
                ]
            },
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "halt": true
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_command"
                }
            ],
            "type": "basic"
        }
    ]
}
handcoding commented 5 years ago

Big props, @elasticdog! That code works a treat. 💯

danielhanold commented 6 months ago

@elasticdog Thanks for sharing that with the community - been trying to make this happen without success for a while until I found your snippet.

sinewave commented 5 months ago

@elasticdog, sorry for reviving an old thread, but I've been trying to get this to work for a long time without any luck until I found your post! 🎉🎉

Do you know how I can use this approach to support multiple keys? For example, using your code above, I've mapped "j" to Cmd and "k" to Shift. I'd like to be able press and hold both to trigger "Cmd + Shift."