0

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?

Community
  • 1
  • 1
twiz
  • 9,041
  • 8
  • 52
  • 84

1 Answers1

1

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
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • Oooops, just tested my suggested aternative with #If (GetKeyState("CapsLock", "P") and GetKeyState("s", "P")), and that doesn't work properly (yet). – Robert Ilbrink Dec 17 '12 at 10:20
  • That is close to what I'm looking for, but I want the Numpad feature to only work while Capslock & s are held down. (Your example is to toggle) – twiz Dec 20 '12 at 01:53