windowsautohotkeykey-bindingskeymapping

Auto Hot Key stopped working after modifying a script


I need to remap certain keys so that CapsLock + "ijkl" would result in arrow keys without actually toggling CapsLock on. Standard practice.

ChatGPT gave me the following code which worked as expected:

CapsLock:: 
    KeyWait, CapsLock  ; Wait until CapsLock is released
    return

#If GetKeyState("CapsLock", "T")  ; Check if CapsLock is toggled on
i::
    Send, {Up}
    return
#If

Then I added more key mappings:

CapsLock:: 
    KeyWait, CapsLock  ; Wait until CapsLock is released
    return


#If GetKeyState("CapsLock", "T")  ; Check if CapsLock is toggled on
i::
    Send, {Up}
    return
j::
    Send, {Left}
    return
k::
    Send, {Down}
    return
l::
    Send, {Right}
    return
#If

And now script runs and only prevents CapsLock from toggling on (seen from LED inactivity on keyboard).

Going back to initial code didn't change anything (still only blocking CapsLock) I tried to launch script with double-click, to launch as administrator, to run with UI access

I did reboot the PC just in case :)

Since the initial code worked fine the first time I guess the problem isn't related to syntax but to some system settings.


Solution

  • A simple script like this would do:

    #Requires AutoHotkey v2.0
    
    capslock & i::Send "{up}"
    capslock & j::Send "{left}"
    capslock & k::Send "{down}"
    capslock & l::Send "{right}"