0
votes

My full goal is to be able to hold down Capslock + s, which will convert the keys uiojklm,. to work like the 10-key number pad.

So as a first step, I am trying to map Capslock + s + m to the number 1

SetCapslockState AlwaysOff

Capslock & s::
keywait, m, d, t0.6
If (!ErrorLevel) {
    SendInput {1}
} Return

I based my current code off of the answer here: Alt + Space + key in autohotkey

When I press Capslock + s + m, it prints out m1. How do I stop the m from printing?

1

1 Answers

1
votes

Here is an alternative solution. You MUST have AutoHotKey_L for this to work since the traditional AutoHotKey does not support #if.

CapsLock & s::
Flag:=!Flag
If (Flag)
    TrayTip, AutoHotKey, Numpad ON, 1
Else
    TrayTip, AutoHotKey, Numpad OFF, 1
Return

#If (Flag)
    m::Send, 0
    k::Send, 1
#If

In the first block you toggle a Flag to True/False with CapsLock + s and you show the status with a traytip, then you define the behaviour of certain keys in the next block. Alternatively you could delete the first block and replace the #if (Flag) line with:

#If (GetKeyState("CapsLock", "P") and GetKeyState("s", "P"))

Update:

Tried the following with varying results. The first (commented out) code does use CapsLock + s, but apparently pressing the s key prevents AutoHotKey from seeing certain other key presses (here the letters n,m,i,o,p worked but j,k,l which are on the same hight/scanline on the keyboard were NOT detected)

SetCapsLockState, alwaysoff

/*
Capslock & s::
While, (GetKeyState("CapsLock", "P") and GetKeyState("s", "P"))
{
    Input, MyKey, I L1 T0.5
    TrayTip, Key:, %MyKey%
    if (MyKey = "m")
        Send, 1
    if (MyKey = "i")
        Send, 2
    if (MyKey = "k")
        Send, 3
    if (MyKey = "j")
        Send, 4
    if (MyKey = "o")
        Send, 5
    if (MyKey = "p")
        Send, 6
}
Return
*/

Just using CapsLock (also on the same like as j,k,l) worked, but that is not what you wanted.

Capslock::
While, (GetKeyState("CapsLock", "P"))
{
    Input, MyKey, I L1 T0.5
    TrayTip, Key:, %MyKey%
    if (MyKey = "m")
        Send, 1
    if (MyKey = "i")
        Send, 2
    if (MyKey = "k")
        Send, 3
    if (MyKey = "j")
        Send, 4
    if (MyKey = "o")
        Send, 5
    if (MyKey = "p")
        Send, 6
}
Return