7

How might I use the CapsLock key as a modifier type key in autohotkey?

For example currently I am currently doing the following:

t=0
CapsLock::t:=!t
#If t 
  y::6
  u::7

Ideally I would like to just be able to hold down the CapsLock key to trigger the keys.

Basically is there a similar way of writing the above code except for the following?

CapsLock & y::6
3
  • I think this questions should be in stackoverflow.com – crazypotato Aug 18 '14 at 17:34
  • @crazypotato Nope, they are fine here. – slhck Aug 18 '14 at 18:17
  • Why you cant use CapsLock & y ? – crazypotato Aug 19 '14 at 9:17
5

If hold down CAPS LOCK

u::
if (GetKeyState("CapsLock")=1){
    u::6
}
else
{
    send u
}

IF TOOGLE CAPS LOCK

u::
if (GetKeyState("CapsLock","t")=1){
    u::6
}
else
{
    send u
}

Get current keyboard layout

Update:

#If GetKeyState("CapsLock")=1
  y::6
  u::7
2
  • I would like to not have to write out the else statement because it is quiet repetitive and not clean – William Aug 19 '14 at 1:36
  • I had to change it to #If GetKeyState("CapsLock", "P") = 1 to work. – mtman Jul 31 '19 at 1:41
6

Here is a much simpler solution:

#SingleInstance, Force

SetCapsLockState, AlwaysOff

;CapsLock & S to open Slack
CapsLock & s::
    Run, Slack.exe
    Return

Note: this will disable the CapsLock key's default behavior

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.