1

I’m using Vim, so I”ve remapped capslock to esc. But I still want capslock sometimes. So I’m wondering to remap shift to shift+capslock:

  1. When shift is used the normal way: Long press and release, it should still work as shift key changing the typing to upper case.
  2. When shift is tapped (short press and release), it should toggle capslock.

Is something like this possible? Does anybody know of any AutoHotkey scripts or tips on how to do this they could share?

  • Are you using Windows? – Vinayak Mar 13 '15 at 3:45
  • yes, autohotkey is only available on windows I think. – Aaron Shen Mar 13 '15 at 3:48
  • That's correct. However, since you mentioned Vim, I wasn't sure. I see now that Vim is available for Windows systems too. – Vinayak Mar 13 '15 at 3:50
  • I'm using terminal based vim in cygwin. But gvim is already available on windows. – Aaron Shen Mar 13 '15 at 3:54
  • This might help. – Vinayak Mar 13 '15 at 4:05
1

Use this AutoHotkey script slightly modified from Elliot DeNolf's answer:

~Shift::
    duration := 0
    If (GetKeyState("Shift","p"))
    {
        start := A_TickCount
        While (GetKeyState("Shift"))
            Sleep, 1
        duration := A_TickCount - start
    }
    if (duration < 100) ;Change this value as needed
        if GetKeyState("CapsLock", "T") = 1
        {
            SetCapsLockState, off
        }
        else if GetKeyState("CapsLock", "T") = 0
        {
            SetCapsLockState, on
        }
    Return

If the Shift key is depressed for less than 100 milliseconds and released, it'll toggle the CapsLk key. Any more than 100 msec and it'll act as a regular modifier key.

If 100 msec is too long, choose an appropriate value in the if condition.

|improve this answer|||||
  • Hi Vinayak, thanks a lot for providing the script. It's working fine for the most of the time. But sometimes when I press down shift key without release it, it will turn on capslock, could you help check? – Aaron Shen Mar 13 '15 at 6:52
  • Are you saying Caps Lock is turned on when you press down Shift and don't release it? – Vinayak Mar 13 '15 at 6:56
  • yeah, assume capslock is turned off now, the light is out. So I'm testing if it's working hold down shift key by watching the capslock if the light remains turned off. But one out of ten times, the light will be turned on, that means the capslock is turned on. – Aaron Shen Mar 13 '15 at 7:18
  • @AaronShen I cannot reproduce the problem you're facing. Maybe something's wrong with your keyboard? You could try adjusting the delay to something more comfortable for you and see if that helps. – Vinayak Mar 13 '15 at 7:30
  • Hi Vinayak, I adjust the key repeat rate, it seems much better now. Thanks – Aaron Shen Mar 13 '15 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.