You can use the Hotkey command to change hotkeys dynamically. Here's a small example how you can remap your keys:
#Persistent
#UseHook
keyMap := {d: "SPACE", f: "j", j: "k", k: "l"}
; Associative objects are AHK_L only!
; for a pseudo array, do something like this:
; keyMapd := "SPACE"
; keymapf := "j"
; ...
Exit
F4::
for orig, new in keyMap
{
Hotkey, %orig%, RemapKey
}
return
RemapKey:
newKey := keyMap[A_ThisHotkey]
; to retrieve from a pseudo array, do this:
; newKey := keyMap%A_ThisHotkey%
Send, {%newKey%}
return
keyMap
is an associative array, mapping the original key with its new target. Pressing F4
will take every key defined in keyMap
and assign it a subroutine called RemapKey
, hence it will be called, when any key in keyMap
(d, f, j or k) is pressed. RemapKey
takes the latest hotkey by accessing A_ThisHotkey
, finds out what it's mapped to and sends that key. The #UseHook
is essential in order to prevent the Send
command to trigger another hotkey (in our case, pressing **F would trigger **J, J would then trigger K and so on).
Note, that the use of associative objects if AutoHotkey_L only. If you're using another version, you'll have to define your map another way (e.g. a pseudo array like keyMapd:="SPACE"
).