Windows – Use CapsLock Key as Modifier Key with AutoHotkey

autohotkeywindows

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

Best Answer

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
Related Question