Skip to content
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 · 122 comments
Closed

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

bosr opened this issue Sep 13, 2016 · 122 comments

Comments

@bosr
Copy link

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 howto short/long press? howto short/long (sticky) keypress? Sep 13, 2016
@bosr
Copy link
Author

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
Copy link

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
Copy link

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

@stylerw
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

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.

@alva-seal
Copy link

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

@bosr
Copy link
Author

bosr commented Sep 23, 2016

@noma4i thanks!

@transtone
Copy link

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

@jasoncodes
Copy link

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

@transtone
Copy link

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

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

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
Copy link

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

@sunapi386
Copy link

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
Copy link

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

@MatthewMDavis
Copy link

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
Copy link

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

@sunapi386
Copy link

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

@leeorengel
Copy link

+1

@zhengpd
Copy link

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.

@axsuul
Copy link

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
Copy link

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
Copy link

cmsj commented Jun 16, 2017

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

@kbairak
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

@wincent Ah, got it, thanks!

@genehack
Copy link

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
Copy link

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

@genehack
Copy link

@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
Copy link

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

@jonathankau
Copy link

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
Copy link

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
Copy link

@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
Copy link
Author

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 as completed Sep 20, 2017
@ddickstein
Copy link

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

@joeybaker
Copy link

Yes. #1131

@ddickstein
Copy link

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
Copy link

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
Copy link

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
Copy link

hk0i commented Mar 29, 2018

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

@elliottw
Copy link

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

@LouiseBC
Copy link

LouiseBC commented Jun 3, 2024

In case anyone is looking for a HHKB-specific version, this worked for me to switch the control key (in caps lock position) to escape/control :)

{
  "description": "Use control as escape when used alone, control when used as a modifier",
  "manipulators": [
    {
      "from": {
        "key_code": "left_control",
        "modifiers": {
          "optional": ["any"]
        }
      },
      "to": [
        {
          "key_code": "left_control"
        }
      ],
      "to_if_alone": [
        {
          "key_code": "escape",
          "modifiers": []
        }
      ],
      "type": "basic"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests