Autohotkey use CapsLock key as modifier key

6

2

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

William

Posted 2014-08-18T15:35:25.997

Reputation: 992

I think this questions should be in stackoverflow.com – crazypotato – 2014-08-18T17:34:22.520

@crazypotato Nope, they are fine here. – slhck – 2014-08-18T18:17:56.697

Why you cant use CapsLock & y ? – crazypotato – 2014-08-19T09:17:00.057

Answers

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

crazypotato

Posted 2014-08-18T15:35:25.997

Reputation: 678

I would like to not have to write out the else statement because it is quiet repetitive and not clean – William – 2014-08-19T01:36:34.107

I had to change it to #If GetKeyState("CapsLock", "P") = 1 to work. – mtman – 2019-07-31T01:41:37.703

4

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

Damien

Posted 2014-08-18T15:35:25.997

Reputation: 140