Setting caps lock key to CTRL but still function as caps lock if I press for long enough in Mac OS X

0

1

If possible I would like something similar to this: https://apple.stackexchange.com/a/4815/31313

Basically a simple script that detects when I'm in tmux, if I am change the CAPS lock key to be a CTRL key, else revert it.

However it is also important for me to use the CAPS lock key from time to time, in those occasions I would like to keep it pressed for 5 seconds, then it triggers a normal CAPS lock.

Would this be easy to do? Possible to do? I would prefer if I don't use any kind of extra software so that I can just put this in a script.

Extra info:

I would want to achieve this in a Mac Mini with OSX Snow Leopard, if possible also with Mountain Lion.

greduan

Posted 2013-01-06T18:32:56.397

Reputation: 363

Answers

2

If you have already changed caps lock to control, adding this to private.xml in KeyRemap4MacBook would make holding control (or caps lock) toggle caps lock:

<autogen>--HoldingKeyToKey-- KeyCode::CONTROL_L, KeyCode::CONTROL_L, KeyCode::VK_NONE, KeyCode::CAPSLOCK, Option::NOREPEAT</autogen>

The threshold for holding keys is 0.2 s by default, but it can be changed in the second tab.

(I suggested changing fn+control (fn+caps lock) to caps lock in the previous question at Ask Different:)

<autogen>--KeyToKey-- KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CAPSLOCK</autogen>

If you just want to keep some key as caps lock, you can also change control to caps lock in System Preferences.

Lri

Posted 2013-01-06T18:32:56.397

Reputation: 34 501

So, I would add <only>TERMINAL</only> after the autogen statement? Or inside it? Would this also work if iTerm is used instead of the Terminal app? Thanks for the tip, although I don't have an fn key with this keyboard (it's a couple of generations of iMac back), you think that would work if I did <kbd>Option+Shift+Caps lock</kbd> instead? – greduan – 2013-01-07T03:21:12.617

Before or after it. But <only>TERMINAL</only> is just Terminal.app, and there's no constant for iTerm. For option and shift, change ModifierFlag::FN to VK_OPTION | VK_SHIFT. – Lri – 2013-01-07T03:29:48.817

OK, so I use <autogen>--HoldingKeyToKey-- KeyCode::CONTROL_L, KeyCode::CONTROL_L, KeyCode::VK_NONE, KeyCode::CAPSLOCK, Option::NOREPEAT</autogen><only>TERMINAL</only> if I want the functionality I requested in the post, after changing the holding key threshold. And I would <autogen>--KeyToKey-- KeyCode::CONTROL_L, VK_OPTION | VK_SHIFT, KeyCode::CAPSLOCK</autogen><only>TERMINAL</only> if I want to remap caps lock to CTRL and press <kbd>Option+Shift+Caps lock</kbd> to switch caps lock. Right? – greduan – 2013-01-07T03:35:37.790

If you wanted caps lock to function as caps lock outside Terminal, you'd need to use PCKeyboardHack to change caps lock to something like F19 and then remap F19.

– Lri – 2013-01-07T03:48:40.403

Ah I see, thanks! Although this does solve it, it doesn't do it with a script so I won't accept it, but it's definitely a workaround. Thanks for looking into this. :) – greduan – 2013-01-07T03:51:02.623