New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

howto short/long (sticky) keypress? (Ctrl/Esc et al.) #8

Closed
bosr opened this Issue Sep 13, 2016 · 121 comments

Comments

Projects
None yet
@bosr

bosr commented Sep 13, 2016

Karabiner-Elements (just installed) works well: many thanks @tekezo !

I would like to setup a feature for CapsLock :

  • short CapsLock keypress = Escape
  • long CapsLock keypress + other key = Control + other key

[edit: I think it was called: Control_L to Control_L (+when you type Control_L only, send Escape)
]

Do you have a template for that or some guidance?

Regards

@bosr bosr changed the title from howto short/long press? to howto short/long (sticky) keypress? Sep 13, 2016

@bosr

This comment has been minimized.

Show comment
Hide comment
@bosr

bosr Sep 13, 2016

After looking at the code and Development.md (thanks for that), I think the closest thing to what was sticky keys behavior is operation_type_post_modifier_flags_struct, but it is not hooked up in the json configuration file, and I am not sure how to use it.

bosr commented Sep 13, 2016

After looking at the code and Development.md (thanks for that), I think the closest thing to what was sticky keys behavior is operation_type_post_modifier_flags_struct, but it is not hooked up in the json configuration file, and I am not sure how to use it.

@sachka

This comment has been minimized.

Show comment
Hide comment
@sachka

sachka Sep 15, 2016

I am also looking forward to this, it seems it won't be placed in simple_modifications, but we don't have a complex example.

sachka commented Sep 15, 2016

I am also looking forward to this, it seems it won't be placed in simple_modifications, but we don't have a complex example.

@mcmillion

This comment has been minimized.

Show comment
Hide comment
@mcmillion

mcmillion Sep 20, 2016

Keeping an eye on this as this is the sole reason I use Karabiner.

mcmillion commented Sep 20, 2016

Keeping an eye on this as this is the sole reason I use Karabiner.

@stylerw

This comment has been minimized.

Show comment
Hide comment
@stylerw

stylerw Sep 21, 2016

This is my main interest as well, as I use a "Hyper Key" setup for Capslock (Escape when tapped, Ctrl+Shift+Cmd+Option when held) as described here:

http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/

stylerw commented Sep 21, 2016

This is my main interest as well, as I use a "Hyper Key" setup for Capslock (Escape when tapped, Ctrl+Shift+Cmd+Option when held) as described here:

http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/

@bosr

This comment has been minimized.

Show comment
Hide comment
@bosr

bosr Sep 21, 2016

Yep, that's also my reference! (along with http://stevelosh.com/blog/2012/10/a-modern-space-cadet/). It was eyes-opening for me.

I use Karabiner to set my actual Control_L key for Hyper, and set CapsLock for Ctrl/Esc.

I use Slate for those Hyper-* shortcuts. This still works by the way, I just have to type Shift+Ctrl+Opt+Cmd instead of my Hyper key...

Cheers

bosr commented Sep 21, 2016

Yep, that's also my reference! (along with http://stevelosh.com/blog/2012/10/a-modern-space-cadet/). It was eyes-opening for me.

I use Karabiner to set my actual Control_L key for Hyper, and set CapsLock for Ctrl/Esc.

I use Slate for those Hyper-* shortcuts. This still works by the way, I just have to type Shift+Ctrl+Opt+Cmd instead of my Hyper key...

Cheers

@noma4i

This comment has been minimized.

Show comment
Hide comment
@noma4i

noma4i Sep 22, 2016

@bosr take a look on HammerSpoon. Iv coupled it with BetterTouchTool to perform some kind of replacement of karabiner.

You never know that you love something until you have lost it

noma4i commented Sep 22, 2016

@bosr take a look on HammerSpoon. Iv coupled it with BetterTouchTool to perform some kind of replacement of karabiner.

You never know that you love something until you have lost it

@clessg

This comment has been minimized.

Show comment
Hide comment
@clessg

clessg Sep 22, 2016

Really looking forward to having this functionality back.

In the mean time, I'm using Keyboard Maestro with these settings. Make sure "is tapped once" is set. Unfortunately, I don't think the delay can be tweaked like it could be in Karabiner, which is sometimes annoying. So I really hope this gets implemented soon.

clessg commented Sep 22, 2016

Really looking forward to having this functionality back.

In the mean time, I'm using Keyboard Maestro with these settings. Make sure "is tapped once" is set. Unfortunately, I don't think the delay can be tweaked like it could be in Karabiner, which is sometimes annoying. So I really hope this gets implemented soon.

@norges

This comment has been minimized.

Show comment
Hide comment
@norges

norges Sep 23, 2016

I also have used seil/karabiner mainly for the esc/control mapping on the caps lock key hope to get it back soon

norges commented Sep 23, 2016

I also have used seil/karabiner mainly for the esc/control mapping on the caps lock key hope to get it back soon

@bosr

This comment has been minimized.

Show comment
Hide comment
@bosr

bosr commented Sep 23, 2016

@noma4i thanks!

@transtone

This comment has been minimized.

Show comment
Hide comment
@transtone

transtone Sep 23, 2016

@clessg which version of keyboard-Maestro u used ? I can't find The Device Key any where of Keyboard-Maestro-7.3

transtone commented Sep 23, 2016

@clessg which version of keyboard-Maestro u used ? I can't find The Device Key any where of Keyboard-Maestro-7.3

@jasoncodes

This comment has been minimized.

Show comment
Hide comment
@jasoncodes

jasoncodes Sep 23, 2016

@transtone “This device key” is in the dropdown as “USB Device Key Trigger”.

jasoncodes commented Sep 23, 2016

@transtone “This device key” is in the dropdown as “USB Device Key Trigger”.

@transtone

This comment has been minimized.

Show comment
Hide comment
@transtone

transtone Sep 23, 2016

thx, I found This device key, but it can't recognize my keyboard.

transtone commented Sep 23, 2016

thx, I found This device key, but it can't recognize my keyboard.

@bosr bosr changed the title from howto short/long (sticky) keypress? to howto short/long (sticky) keypress? (Ctrl/Esc et al.) Sep 23, 2016

@MatthewMDavis

This comment has been minimized.

Show comment
Hide comment
@MatthewMDavis

MatthewMDavis Sep 23, 2016

Tough to oversell the importance of this feature. I just upgraded to Sierra and realized I had accidentally broken all my muscle memory. I was starting to like the 'ubiquitous vim' feature, but the multi-function Ctrl/Esc key instead of Caps Lock will take me months of coding to unlearn.

Is it coming back, or do I need to resign myself to an ugly future?

MatthewMDavis commented Sep 23, 2016

Tough to oversell the importance of this feature. I just upgraded to Sierra and realized I had accidentally broken all my muscle memory. I was starting to like the 'ubiquitous vim' feature, but the multi-function Ctrl/Esc key instead of Caps Lock will take me months of coding to unlearn.

Is it coming back, or do I need to resign myself to an ugly future?

@jluckyiv

This comment has been minimized.

Show comment
Hide comment
@jluckyiv

jluckyiv Sep 23, 2016

@clessg thanks for the tip. I got mine working based on your tip. I do miss Seil.

jluckyiv commented Sep 23, 2016

@clessg thanks for the tip. I got mine working based on your tip. I do miss Seil.

@sunapi386

This comment has been minimized.

Show comment
Hide comment
@sunapi386

sunapi386 Sep 23, 2016

In karabiner.json, how does one map fn to a hyper key? For example, pressing fn and having it mapped to control+shift+option+command.

sunapi386 commented Sep 23, 2016

In karabiner.json, how does one map fn to a hyper key? For example, pressing fn and having it mapped to control+shift+option+command.

@juanibiapina

This comment has been minimized.

Show comment
Hide comment
@juanibiapina

juanibiapina Sep 23, 2016

@MatthewMDavis I got really desperate too, but the solution with keyboard maestro works for now (even though the software is horrible).

juanibiapina commented Sep 23, 2016

@MatthewMDavis I got really desperate too, but the solution with keyboard maestro works for now (even though the software is horrible).

@MatthewMDavis

This comment has been minimized.

Show comment
Hide comment
@MatthewMDavis

MatthewMDavis Sep 24, 2016

Well, hopefully a trial period of Keyboard Maestro will let me limp along until Karabiner Elements picks up the slack. Thanks to all for the recommendation of a fix. RSI staved off for now.

MatthewMDavis commented Sep 24, 2016

Well, hopefully a trial period of Keyboard Maestro will let me limp along until Karabiner Elements picks up the slack. Thanks to all for the recommendation of a fix. RSI staved off for now.

@mcmillion

This comment has been minimized.

Show comment
Hide comment
@mcmillion

mcmillion Sep 26, 2016

I actually rolled back to El Cap until this gets implemented. I tried but I just couldn't unlearn it.

mcmillion commented Sep 26, 2016

I actually rolled back to El Cap until this gets implemented. I tried but I just couldn't unlearn it.

@sunapi386

This comment has been minimized.

Show comment
Hide comment
@sunapi386

sunapi386 Sep 26, 2016

@mcmillion Wish it was that easy for the rest of us 😏

sunapi386 commented Sep 26, 2016

@mcmillion Wish it was that easy for the rest of us 😏

@leeorengel

This comment has been minimized.

Show comment
Hide comment
@leeorengel

leeorengel commented Sep 26, 2016

+1

@zhengpd

This comment has been minimized.

Show comment
Hide comment
@zhengpd

zhengpd Sep 27, 2016

I'm using Emacs and like to map held-down Enter key to Ctrl, which is the primary reason I used Karabiner on El Capitan. Haven't found a solution to this on Sierra yet.

zhengpd commented Sep 27, 2016

I'm using Emacs and like to map held-down Enter key to Ctrl, which is the primary reason I used Karabiner on El Capitan. Haven't found a solution to this on Sierra yet.

@vladshablinsky

This comment has been minimized.

Show comment
Hide comment
@vladshablinsky

vladshablinsky Sep 27, 2016

Well, I'll leave my comment with my use case as well as everybody else in case it helps.
I use vim and tmux and it's handy when caps lock is mapped to escape and when you press it with some other key It acts like control e.g. useful for tmux prefix. I hope you will implement this behaviour. 🙁😔

vladshablinsky commented Sep 27, 2016

Well, I'll leave my comment with my use case as well as everybody else in case it helps.
I use vim and tmux and it's handy when caps lock is mapped to escape and when you press it with some other key It acts like control e.g. useful for tmux prefix. I hope you will implement this behaviour. 🙁😔

@tommyc38

This comment has been minimized.

Show comment
Hide comment
@tommyc38

tommyc38 Sep 30, 2016

+1 @clessg Note, that you need to make sure Keyboard Maestro has access to everything under your privacy settings. I was knocking my head around for an hour trying to figure out why the hell it wasn't picking up my keys!

tommyc38 commented Sep 30, 2016

+1 @clessg Note, that you need to make sure Keyboard Maestro has access to everything under your privacy settings. I was knocking my head around for an hour trying to figure out why the hell it wasn't picking up my keys!

@vbauerster

This comment has been minimized.

Show comment
Hide comment

vbauerster commented Sep 30, 2016

@axsuul

This comment has been minimized.

Show comment
Hide comment
@axsuul

axsuul Sep 30, 2016

@vbauerster Requires a Time Machine backup which most of us probably don't have :(

axsuul commented Sep 30, 2016

@vbauerster Requires a Time Machine backup which most of us probably don't have :(

@arbelt

This comment has been minimized.

Show comment
Hide comment
@arbelt

arbelt Oct 2, 2016

For anyone else waiting on this, I've discovered that it's possible to mimic the behavior using hs.eventtap from Hammerspoon. It won't distinguish between Ctrl_L and Ctrl_R, but it does the trick for me:

https://gist.github.com/arbelt/b91e1f38a0880afb316dd5b5732759f1

There are some things that might make it better, like monitoring for other presses and disabling the sending of escape in that case, but I use a pretty short delay (150 ms) so that it's unlikely to press, say, Ctrl-A and still trigger the Escape.

arbelt commented Oct 2, 2016

For anyone else waiting on this, I've discovered that it's possible to mimic the behavior using hs.eventtap from Hammerspoon. It won't distinguish between Ctrl_L and Ctrl_R, but it does the trick for me:

https://gist.github.com/arbelt/b91e1f38a0880afb316dd5b5732759f1

There are some things that might make it better, like monitoring for other presses and disabling the sending of escape in that case, but I use a pretty short delay (150 ms) so that it's unlikely to press, say, Ctrl-A and still trigger the Escape.

@ravicious

This comment has been minimized.

Show comment
Hide comment
@ravicious

ravicious Oct 2, 2016

I'd like to take this opportunity to remind everybody that tekezo accepts donations which are much more helpful than "+1" comments. I'd rather send tekezo $10 than buy a $36 Keyboard Maestro license.

ravicious commented Oct 2, 2016

I'd like to take this opportunity to remind everybody that tekezo accepts donations which are much more helpful than "+1" comments. I'd rather send tekezo $10 than buy a $36 Keyboard Maestro license.

@mcmillion

This comment has been minimized.

Show comment
Hide comment
@mcmillion

mcmillion Oct 2, 2016

I definitely donated. Im just letting tekezo know what my donation was for ;)

mcmillion commented Oct 2, 2016

I definitely donated. Im just letting tekezo know what my donation was for ;)

@ivanbrennan

This comment has been minimized.

Show comment
Hide comment
@ivanbrennan

ivanbrennan Jun 12, 2017

I've been using 0.90.83 for several months. I do the caps-lock/control/escape thing, and similarly semicolon as a control modifier and normal semicolon when tapped.

I just noticed (it's probably been like this all along) that if I hold down shift+semicolon (in an attempt to type a long line of repeated colons), it does nothing. The events viewer shows it's registering a shift+control hold.

I've been holding off on updating because I've got a stable build and didn't want to rock the boat, but I noticed it sounds like 0.90.86-2 may have fixed this issue.

fixed the case when continuous standalone keys are pressed

@wwwjfy Is that referring to the issue I'm seeing?

my karabiner.json:

{
    "global": {
        "check_for_updates_on_startup": true,
        "show_in_menu_bar": true
    },
    "profiles": [
        {
            "devices": [],
            "fn_function_keys": {
                "f1": "display_brightness_decrement",
                "f10": "mute",
                "f11": "volume_decrement",
                "f12": "volume_increment",
                "f2": "display_brightness_increment",
                "f3": "mission_control",
                "f4": "launchpad",
                "f5": "illumination_decrement",
                "f6": "illumination_increment",
                "f7": "rewind",
                "f8": "play_or_pause",
                "f9": "fastforward"
            },
            "name": "Default profile",
            "selected": true,
            "simple_modifications": {
                "caps_lock": "left_control",
                "semicolon": "right_control"
            },
            "standalone_keys": {
                "caps_lock": "escape",
                "semicolon": "semicolon"
            },
            "virtual_hid_keyboard": {
                "caps_lock_delay_milliseconds": 0,
                "keyboard_type": "ansi",
                "standalone_keys_delay_milliseconds": 250
            }
        }
    ]
}

ivanbrennan commented Jun 12, 2017

I've been using 0.90.83 for several months. I do the caps-lock/control/escape thing, and similarly semicolon as a control modifier and normal semicolon when tapped.

I just noticed (it's probably been like this all along) that if I hold down shift+semicolon (in an attempt to type a long line of repeated colons), it does nothing. The events viewer shows it's registering a shift+control hold.

I've been holding off on updating because I've got a stable build and didn't want to rock the boat, but I noticed it sounds like 0.90.86-2 may have fixed this issue.

fixed the case when continuous standalone keys are pressed

@wwwjfy Is that referring to the issue I'm seeing?

my karabiner.json:

{
    "global": {
        "check_for_updates_on_startup": true,
        "show_in_menu_bar": true
    },
    "profiles": [
        {
            "devices": [],
            "fn_function_keys": {
                "f1": "display_brightness_decrement",
                "f10": "mute",
                "f11": "volume_decrement",
                "f12": "volume_increment",
                "f2": "display_brightness_increment",
                "f3": "mission_control",
                "f4": "launchpad",
                "f5": "illumination_decrement",
                "f6": "illumination_increment",
                "f7": "rewind",
                "f8": "play_or_pause",
                "f9": "fastforward"
            },
            "name": "Default profile",
            "selected": true,
            "simple_modifications": {
                "caps_lock": "left_control",
                "semicolon": "right_control"
            },
            "standalone_keys": {
                "caps_lock": "escape",
                "semicolon": "semicolon"
            },
            "virtual_hid_keyboard": {
                "caps_lock_delay_milliseconds": 0,
                "keyboard_type": "ansi",
                "standalone_keys_delay_milliseconds": 250
            }
        }
    ]
}
@jasonrudolph

This comment has been minimized.

Show comment
Hide comment
@jasonrudolph

jasonrudolph Jun 12, 2017

I would like to setup a feature for CapsLock :

  • short CapsLock keypress = Escape
  • long CapsLock keypress + other key = Control + other key

As an adaptation of @arbelt's work in #8 (comment), ControlEscape.spoon provides this ☝️ functionality with a (mostly) automated setup process. There's a good chance that you can get it installed and running in less than a minute. 😅

I hope this helps. If you try it out and run into any problems, please open an issue to let me know.

jasonrudolph commented Jun 12, 2017

I would like to setup a feature for CapsLock :

  • short CapsLock keypress = Escape
  • long CapsLock keypress + other key = Control + other key

As an adaptation of @arbelt's work in #8 (comment), ControlEscape.spoon provides this ☝️ functionality with a (mostly) automated setup process. There's a good chance that you can get it installed and running in less than a minute. 😅

I hope this helps. If you try it out and run into any problems, please open an issue to let me know.

@oliverxchen

This comment has been minimized.

Show comment
Hide comment
@oliverxchen

oliverxchen Jun 12, 2017

@jasonrudolph that looks great! Have you tested this and https://github.com/jasonrudolph/keyboard with Mac OS 10.12.5? I've been holding off on that upgrade cause I saw a comment saying that it broke the fix to make CapsLock useful.

oliverxchen commented Jun 12, 2017

@jasonrudolph that looks great! Have you tested this and https://github.com/jasonrudolph/keyboard with Mac OS 10.12.5? I've been holding off on that upgrade cause I saw a comment saying that it broke the fix to make CapsLock useful.

@wwwjfy

This comment has been minimized.

Show comment
Hide comment
@wwwjfy

wwwjfy Jun 12, 2017

Contributor

@ivanbrennan Yes, please try to use the latest build. If anything goes wrong, you can always revert to the old version

Contributor

wwwjfy commented Jun 12, 2017

@ivanbrennan Yes, please try to use the latest build. If anything goes wrong, you can always revert to the old version

@ivanbrennan

This comment has been minimized.

Show comment
Hide comment
@ivanbrennan

ivanbrennan Jun 12, 2017

@wwwjfy Thanks for the fast response. I installed the latest (0.90.92) and rebooted. Unfortunately, the behavior is unchanged, i.e. holding down shift+semicolon registers as a continuous shift+control rather than a repeated colon.

Not a huge deal, as it's not that often you need to type a long line of colons (well, maybe in C++ 😄 ).

I'm curious though, has anyone else run into this?

ivanbrennan commented Jun 12, 2017

@wwwjfy Thanks for the fast response. I installed the latest (0.90.92) and rebooted. Unfortunately, the behavior is unchanged, i.e. holding down shift+semicolon registers as a continuous shift+control rather than a repeated colon.

Not a huge deal, as it's not that often you need to type a long line of colons (well, maybe in C++ 😄 ).

I'm curious though, has anyone else run into this?

@wwwjfy

This comment has been minimized.

Show comment
Hide comment
@wwwjfy

wwwjfy Jun 12, 2017

Contributor

@ivanbrennan You're right.
Sorry I didn't read your comment carefully.

It's now designed to be like this, for the cases you want to press shift+ctrl+(any other key). If it works as you expect, there is no way (I can now think of) to make it behavior like ctrl.

I see it a compromise, other than a bug. If you can think of a way to achieve both, please let me know. I'm happy to fix that.

Contributor

wwwjfy commented Jun 12, 2017

@ivanbrennan You're right.
Sorry I didn't read your comment carefully.

It's now designed to be like this, for the cases you want to press shift+ctrl+(any other key). If it works as you expect, there is no way (I can now think of) to make it behavior like ctrl.

I see it a compromise, other than a bug. If you can think of a way to achieve both, please let me know. I'm happy to fix that.

@ivanbrennan

This comment has been minimized.

Show comment
Hide comment
@ivanbrennan

ivanbrennan Jun 12, 2017

@wwwjfy Got it, that makes sense.

Maybe we could use karabiner.json to specify a binding for the ordered combination shift+key that takes precedence over key's simple-modification. I imagine something like,

"simple_modifications": {
    "semicolon": "right_control"
},
"ordered_modifications": {
    "shift": {
        "semicolon": "colon"
    }
},
"standalone_keys": {
    "semicolon": "semicolon"
},

allowing shift+; to send :, and ;+shift to act as control+shift.

ivanbrennan commented Jun 12, 2017

@wwwjfy Got it, that makes sense.

Maybe we could use karabiner.json to specify a binding for the ordered combination shift+key that takes precedence over key's simple-modification. I imagine something like,

"simple_modifications": {
    "semicolon": "right_control"
},
"ordered_modifications": {
    "shift": {
        "semicolon": "colon"
    }
},
"standalone_keys": {
    "semicolon": "semicolon"
},

allowing shift+; to send :, and ;+shift to act as control+shift.

@jasonrudolph

This comment has been minimized.

Show comment
Hide comment
@jasonrudolph

jasonrudolph Jun 12, 2017

ControlEscape.spoon provides this ☝️ functionality with a (mostly) automated setup process.

Have you tested this and https://github.com/jasonrudolph/keyboard with Mac OS 10.12.5?

@oliverxchen: Yes. I'm actively using them both on macOS 10.12.5. 👌

If you run into any problems, please open an issue on one of those repositories.

jasonrudolph commented Jun 12, 2017

ControlEscape.spoon provides this ☝️ functionality with a (mostly) automated setup process.

Have you tested this and https://github.com/jasonrudolph/keyboard with Mac OS 10.12.5?

@oliverxchen: Yes. I'm actively using them both on macOS 10.12.5. 👌

If you run into any problems, please open an issue on one of those repositories.

@karansag

This comment has been minimized.

Show comment
Hide comment
@karansag

karansag Jun 13, 2017

Hi all, and thanks @wwwjfy for the fork. It works wonderfully!

One quick question: is profile switching supposed to work in this or @tekezo 's Karabiner-Elements? I'm on 0.90.92, macOS 10.12.5, and with multiple profiles I notice that I have to restart Karabiner-Elements for an alternate profile to take effect.

karansag commented Jun 13, 2017

Hi all, and thanks @wwwjfy for the fork. It works wonderfully!

One quick question: is profile switching supposed to work in this or @tekezo 's Karabiner-Elements? I'm on 0.90.92, macOS 10.12.5, and with multiple profiles I notice that I have to restart Karabiner-Elements for an alternate profile to take effect.

@wwwjfy

This comment has been minimized.

Show comment
Hide comment
@wwwjfy

wwwjfy Jun 14, 2017

Contributor

@ivanbrennan I think the introduced complexity may not worth it because bugs can be introduced, too.

@karansag Once you edited the karabiner.json, it'll reload the configuration automatically. You can see that in the "Log" tab of the app. Or you can use /Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli --select-profile xxx to switch

Contributor

wwwjfy commented Jun 14, 2017

@ivanbrennan I think the introduced complexity may not worth it because bugs can be introduced, too.

@karansag Once you edited the karabiner.json, it'll reload the configuration automatically. You can see that in the "Log" tab of the app. Or you can use /Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli --select-profile xxx to switch

@ivanbrennan

This comment has been minimized.

Show comment
Hide comment
@ivanbrennan

ivanbrennan commented Jun 14, 2017

@wwwjfy Yeah, I agree.

@zeekay

This comment has been minimized.

Show comment
Hide comment
@zeekay

zeekay Jun 16, 2017

This is now natively supported in 0.91.3+

Example ~/.config/karabiner/karabiner.json:

{
    "profiles": [
        {
            "complex_modifications": {
                "rules": [
                    {
                        "manipulators": [
                            {
                                "description": "Change caps_lock to control when used as modifier, escape when used alone",
                                "from": {
                                    "key_code": "caps_lock",
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "left_control"
                                    }
                                ],
                                "to_if_alone": [
                                    {
                                        "key_code": "escape",
                                        "modifiers": {
                                            "optional": [
                                                "any"
                                            ]
                                        }
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

Thanks for your interim solution @wwwjfy!

zeekay commented Jun 16, 2017

This is now natively supported in 0.91.3+

Example ~/.config/karabiner/karabiner.json:

{
    "profiles": [
        {
            "complex_modifications": {
                "rules": [
                    {
                        "manipulators": [
                            {
                                "description": "Change caps_lock to control when used as modifier, escape when used alone",
                                "from": {
                                    "key_code": "caps_lock",
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "left_control"
                                    }
                                ],
                                "to_if_alone": [
                                    {
                                        "key_code": "escape",
                                        "modifiers": {
                                            "optional": [
                                                "any"
                                            ]
                                        }
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

Thanks for your interim solution @wwwjfy!

@axsuul

This comment has been minimized.

Show comment
Hide comment
@axsuul

axsuul Jun 16, 2017

@zeekay This is exciting! Has there been any documentation yet or examples of how to fully take advantage of complex_modifications?

axsuul commented Jun 16, 2017

@zeekay This is exciting! Has there been any documentation yet or examples of how to fully take advantage of complex_modifications?

@atomkirk

This comment has been minimized.

Show comment
Hide comment
@atomkirk

atomkirk Jun 16, 2017

Supported "natively" meaning in the main project fork?

Tip: you need to remove any simple_modification of caps to escape for this to work.

atomkirk commented Jun 16, 2017

Supported "natively" meaning in the main project fork?

Tip: you need to remove any simple_modification of caps to escape for this to work.

@cmsj

This comment has been minimized.

Show comment
Hide comment
@cmsj

cmsj Jun 16, 2017

@axsuul: look in the examples directory in the code, there's some in there :)

cmsj commented Jun 16, 2017

@axsuul: look in the examples directory in the code, there's some in there :)

@kbairak

This comment has been minimized.

Show comment
Hide comment
@kbairak

kbairak Jul 4, 2017

@zeekay I did the same thing too, worked like a charm (also did "right_shift to right_shift, backslash if alone" because European keyboards suck).

Then I realized that if I mapped left_control or escape to caps_lock, either via simple or complex modification, all keys would work the same way (escape if alone, left_control otherwise). So now, I can't find any way of having a caps_lock key.

Any chance someone has figured this one out?

kbairak commented Jul 4, 2017

@zeekay I did the same thing too, worked like a charm (also did "right_shift to right_shift, backslash if alone" because European keyboards suck).

Then I realized that if I mapped left_control or escape to caps_lock, either via simple or complex modification, all keys would work the same way (escape if alone, left_control otherwise). So now, I can't find any way of having a caps_lock key.

Any chance someone has figured this one out?

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Jul 5, 2017

@kbairak. Not sure if I understand your question, but I have L-Shift + R-Shift together mapped to Caps Lock, which frees up the Caps Lock key to be mapped to Backspace (Colemak) + Control.

wincent commented Jul 5, 2017

@kbairak. Not sure if I understand your question, but I have L-Shift + R-Shift together mapped to Caps Lock, which frees up the Caps Lock key to be mapped to Backspace (Colemak) + Control.

@ivanbrennan

This comment has been minimized.

Show comment
Hide comment
@ivanbrennan

ivanbrennan Jul 27, 2017

Can anyone explain the effect of the to_if_alone_timeout_milliseconds setting? From the name, I expected it would affect the delay used to distinguish a stand-alone keypress from a chorded press, but even if I set it super high (3000), I can't perceive any difference.

For context, I'm talking about the setting that shows up here:

"profiles": [
    {
        "complex_modifications": {
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 1000

ivanbrennan commented Jul 27, 2017

Can anyone explain the effect of the to_if_alone_timeout_milliseconds setting? From the name, I expected it would affect the delay used to distinguish a stand-alone keypress from a chorded press, but even if I set it super high (3000), I can't perceive any difference.

For context, I'm talking about the setting that shows up here:

"profiles": [
    {
        "complex_modifications": {
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 1000
@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Jul 27, 2017

@ivanbrennan: Just say you have caps lock set to fire backspace if pressed alone, or act as control if pressed with another key:

  • Hold caps lock for 995 ms, release: it fires backspace.
  • Hold caps lock for 1005 ms, release: it does nothing (shows up in event viewer as control-down, control-up).

1000ms is the default. I set it to 500ms in my set-up and I believe (subjectively) that I was able to notice the effect I described above.

wincent commented Jul 27, 2017

@ivanbrennan: Just say you have caps lock set to fire backspace if pressed alone, or act as control if pressed with another key:

  • Hold caps lock for 995 ms, release: it fires backspace.
  • Hold caps lock for 1005 ms, release: it does nothing (shows up in event viewer as control-down, control-up).

1000ms is the default. I set it to 500ms in my set-up and I believe (subjectively) that I was able to notice the effect I described above.

@ivanbrennan

This comment has been minimized.

Show comment
Hide comment
@ivanbrennan

ivanbrennan Jul 27, 2017

@wincent Ah, got it, thanks!

ivanbrennan commented Jul 27, 2017

@wincent Ah, got it, thanks!

bohuim added a commit to bohuim/dotfiles that referenced this issue Aug 11, 2017

Changes:
+ Added config to bind CAPS to CTRL/ESC <tekezo/Karabiner-Elements#8 (comment)>
@genehack

This comment has been minimized.

Show comment
Hide comment
@genehack

genehack Aug 13, 2017

FWIW, these recent changes have allowed me to get back to my preferred keyconfig: using the shift keys by themselves as left and right parens, requiring "proper" shift key usage (i.e., left side keys with right shift, and vice versa), and disabling shift-9 and shift-0 completely (so as to force the use of the shift keys for parens). Thanks to everybody that's participated on this thread. 8^)

genehack commented Aug 13, 2017

FWIW, these recent changes have allowed me to get back to my preferred keyconfig: using the shift keys by themselves as left and right parens, requiring "proper" shift key usage (i.e., left side keys with right shift, and vice versa), and disabling shift-9 and shift-0 completely (so as to force the use of the shift keys for parens). Thanks to everybody that's participated on this thread. 8^)

@BerkeleyTrue

This comment has been minimized.

Show comment
Hide comment
@BerkeleyTrue

BerkeleyTrue Aug 13, 2017

@genehack How where you able to disable shift 0/9? I wasn't able to get this to work on my side

BerkeleyTrue commented Aug 13, 2017

@genehack How where you able to disable shift 0/9? I wasn't able to get this to work on my side

@genehack

This comment has been minimized.

Show comment
Hide comment
@genehack

genehack Aug 13, 2017

@BerkeleyTrue See here for shift-9 and here for shift-0.

Note also that there are other parts of the config that disable right_shift with 0 and 9 (as part of a generalized "require the proper shift and command key usage" setup), so the above config only disables with left_shift.

genehack commented Aug 13, 2017

@BerkeleyTrue See here for shift-9 and here for shift-0.

Note also that there are other parts of the config that disable right_shift with 0 and 9 (as part of a generalized "require the proper shift and command key usage" setup), so the above config only disables with left_shift.

@BerkeleyTrue

This comment has been minimized.

Show comment
Hide comment
@BerkeleyTrue

BerkeleyTrue Aug 13, 2017

@genehack Thanks, That did it for me. Happy Coding.

BerkeleyTrue commented Aug 13, 2017

@genehack Thanks, That did it for me. Happy Coding.

@jonathankau

This comment has been minimized.

Show comment
Hide comment
@jonathankau

jonathankau Sep 14, 2017

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 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. If anyone's done something like that in a fork, let me know!

jonathankau commented Sep 14, 2017

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 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. If anyone's done something like that in a fork, let me know!

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Sep 15, 2017

@jonathankau: I suspect that what you need is what used to be called __BlockUntilKeyUp__ in the old Karabiner. I created an issue for that a while back (#877).

wincent commented Sep 15, 2017

@jonathankau: I suspect that what you need is what used to be called __BlockUntilKeyUp__ in the old Karabiner. I created an issue for that a while back (#877).

@jonathankau

This comment has been minimized.

Show comment
Hide comment
@jonathankau

jonathankau Sep 15, 2017

@wincent At first I thought that was exactly what I needed, but after checking the EventViewer it turns out that the way I generally activate shortcuts is via a CMD down ---> C down ---> CMD up ---> C up flow.

jonathankau commented Sep 15, 2017

@wincent At first I thought that was exactly what I needed, but after checking the EventViewer it turns out that the way I generally activate shortcuts is via a CMD down ---> C down ---> CMD up ---> C up flow.

@bosr

This comment has been minimized.

Show comment
Hide comment
@bosr

bosr Sep 20, 2017

Well, I close this issue because the latest karabiner-elements now implements it perfectly (#247). Many thanks to @tekezo, @wwwjfy and the community!

bosr commented Sep 20, 2017

Well, I close this issue because the latest karabiner-elements now implements it perfectly (#247). Many thanks to @tekezo, @wwwjfy and the community!

@bosr bosr closed this Sep 20, 2017

@ddickstein

This comment has been minimized.

Show comment
Hide comment
@ddickstein

ddickstein Nov 20, 2017

Will this continue to work on High Sierra? Not sure if I should upgrade if not.

ddickstein commented Nov 20, 2017

Will this continue to work on High Sierra? Not sure if I should upgrade if not.

@joeybaker

This comment has been minimized.

Show comment
Hide comment
@joeybaker

joeybaker commented Nov 20, 2017

Yes. #1131

@ddickstein

This comment has been minimized.

Show comment
Hide comment
@ddickstein

ddickstein Nov 20, 2017

Follow up question - if I enable "change caps_lock to control if pressed with other keys, to escape if pressed alone" it disables my simple rule of mapping the escape key to caps lock and the escape key continues to work like escape. How can I get escape working like caps while caps working like escape if tapped and ctrl if pressed with other keys?

(update: it seems it causes any key mapped to caps to instead behave like escape b/c of this rule that changes how the caps key code is processed. I'd like only actually pressing caps lock to trigger this ctrl/esc behavior, while allowing other keys to trigger the normal caps functionality).

ddickstein commented Nov 20, 2017

Follow up question - if I enable "change caps_lock to control if pressed with other keys, to escape if pressed alone" it disables my simple rule of mapping the escape key to caps lock and the escape key continues to work like escape. How can I get escape working like caps while caps working like escape if tapped and ctrl if pressed with other keys?

(update: it seems it causes any key mapped to caps to instead behave like escape b/c of this rule that changes how the caps key code is processed. I'd like only actually pressing caps lock to trigger this ctrl/esc behavior, while allowing other keys to trigger the normal caps functionality).

@wardch

This comment has been minimized.

Show comment
Hide comment
@wardch

wardch Dec 1, 2017

After struggling for a while I found a reliable way to get caps lock to be escape when tapped and control when held on High Sierra without modifying the ~/.config/karabiner/karabiner.json file directly.

  1. First follow the instructions in Jeff Gerlings blog: https://www.jeffgeerling.com/blog/2017/remapping-caps-lock-key-escape-macos-sierra

  2. Then open up karbiner elements and go to the complex rule section, and go to complex modifications. Then go to add a rule, there is an import more rules from the internet button, hit it and it'll take you to: https://pqrs.org/osx/karabiner/complex_modifications/

  3. Import Change caps lock key, and then all you have to do is select:
    Change caps_lock to control if pressed with other keys, to escape if pressed alone.

  4. Make sure that is the only rule selected in the simple and complex modification tabs, then you should be good to go!

wardch commented Dec 1, 2017

After struggling for a while I found a reliable way to get caps lock to be escape when tapped and control when held on High Sierra without modifying the ~/.config/karabiner/karabiner.json file directly.

  1. First follow the instructions in Jeff Gerlings blog: https://www.jeffgeerling.com/blog/2017/remapping-caps-lock-key-escape-macos-sierra

  2. Then open up karbiner elements and go to the complex rule section, and go to complex modifications. Then go to add a rule, there is an import more rules from the internet button, hit it and it'll take you to: https://pqrs.org/osx/karabiner/complex_modifications/

  3. Import Change caps lock key, and then all you have to do is select:
    Change caps_lock to control if pressed with other keys, to escape if pressed alone.

  4. Make sure that is the only rule selected in the simple and complex modification tabs, then you should be good to go!

@marlonbernardes

This comment has been minimized.

Show comment
Hide comment
@marlonbernardes

marlonbernardes Feb 16, 2018

Since I was only using Seil/Karabiner to remap caps lockF19 and F19 to Esc (when tapping) / Ctrl (holding) and this feature does not seem to be supported, this is what I ended up doing to achieve the same results without using Seil/Karabiner:

  1. close karabiner/seil if they are still open (optionally uninstall them)
  2. Execute the script below
# It assumes you have `homebrew` already installed.
mkdir -p ~/.hammerspoon/Spoons
git clone https://github.com/jasonrudolph/ControlEscape.spoon.git ~/.hammerspoon/Spoons/ControlEscape.spoon
cd ~/.hammerspoon/Spoons/ControlEscape.spoon
script/setup
  1. Give accessibility access to hammerspoon (Settings -> Security and Privacy -> Privacy tab)
    image

  2. This will change the behaviour of your Ctrl (so it sends Esc when tapped). Now all you gotta do is to remap your Caps Lock to Ctrl (Settings -> Keyboard -> modifier keys):

image

marlonbernardes commented Feb 16, 2018

Since I was only using Seil/Karabiner to remap caps lockF19 and F19 to Esc (when tapping) / Ctrl (holding) and this feature does not seem to be supported, this is what I ended up doing to achieve the same results without using Seil/Karabiner:

  1. close karabiner/seil if they are still open (optionally uninstall them)
  2. Execute the script below
# It assumes you have `homebrew` already installed.
mkdir -p ~/.hammerspoon/Spoons
git clone https://github.com/jasonrudolph/ControlEscape.spoon.git ~/.hammerspoon/Spoons/ControlEscape.spoon
cd ~/.hammerspoon/Spoons/ControlEscape.spoon
script/setup
  1. Give accessibility access to hammerspoon (Settings -> Security and Privacy -> Privacy tab)
    image

  2. This will change the behaviour of your Ctrl (so it sends Esc when tapped). Now all you gotta do is to remap your Caps Lock to Ctrl (Settings -> Keyboard -> modifier keys):

image

@hk0i

This comment has been minimized.

Show comment
Hide comment
@hk0i

hk0i Mar 29, 2018

This is the only feature I was looking for...

hk0i commented Mar 29, 2018

This is the only feature I was looking for...

@elliottw

This comment has been minimized.

Show comment
Hide comment
@elliottw

elliottw Apr 27, 2018

so #8 (comment) did not work for me, but #8 (comment) did. I'm running 10.13.3 not sure why.

elliottw commented Apr 27, 2018

so #8 (comment) did not work for me, but #8 (comment) did. I'm running 10.13.3 not sure why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment