0
votes

I have a few key mappings and macros I use via AutoHotkey. I have remapped control to capslock and I made a macro that lets me press ^, for home and ^. for end. This works perfectly fine if I press capslock and ',' or '.' once. But if I continue to hold down capslock and then press ',' or '.' again it just inserts the character. I get the expected behavior when I hold down the actual capslock key.

I've tried the suggestions from the answer in this question: Autohotkey, issue after mapping capslock::ctrl and that works -- except it changes the behavior from start/end of line to start/end of file.

Here is my code:

^,::Send, {Home}
^.::Send, {End}
Capslock::Ctrl
2

2 Answers

1
votes

There are many possible complications when directly mapping CapsLock to a key. I would suggest you go the route of setting a variable when CapsLock is held down. Here is how I would suggest you do it for AutoHotkey_L.

global capDown = 0

CapsLock::
    capDown = 1
return

CapsLock up::
    capDown = 0
return


#If capDown
    *h::CapsNav("Left")
    *j::CapsNav("Down")
    *k::CapsNav("Up")
    *l::CapsNav("Right")

    *,::CapsNav("Home")
    *.::CapsNav("End")

    *n::CapsNav("Home", "^")
    *p::CapsNav("End", "^")

    *a::Send ^a ; add as needed



CapsNav(action, initmod = "", mod = "+")
{
    If ! GetKeyState("alt")
        Send % initmod "{" action "}"
    Else
        Send % mod . initmod "{" action "}"
    SetCapsLockState, AlwaysOff
}

For the recent version of AutoHotkey remove global and change #If capDown to if (capDown)

The included function also allows Alt to be held down to select text while moving. It also allows a modifier such as Ctrl to be used.

If you use CapsLock for other key combinations, you will want to add all of those as well. Hope this helps.

0
votes

Not sure why you have this behaviour.

I tried this to test and it works fine multiple times with both Ctrl or CapsLock pressed all the time.

Capslock::Ctrl
^,::SoundBeep, 300, 500
^.::SoundBeep, 1000, 500