Monday, December 1, 2014

keyboard - How to map “shift” key to “shift” + “capslock” using AutoHotkey?


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?


Answer



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.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...