Doing exactly what you want is not possible in AutoHotkey. This is the closest way I can think of.
Call this file Hotkeys.ahk and put it in My Documents/AutoHotkey/Lib . Alternatively, create a folder named Lib and put it in the same directory as your main script.
Hotkeys := {} Hotkey(hk, fun, p*) { global hotkeys hotkeys[hk] := {} hotkeys[hk].fun := fun hotkeys[hk].p := p Hotkey, %hk%, HandleHotkey } HandleHotkey: hotkeys[A_ThisHotkey].fun(hotkeys[A_ThisHotkey].p*) return
Here is an example script with which you could use it.
Hotkey("e", "msgbox", "foobar") MsgBox(msg) { msgbox % msg } #Include <Hotkeys>
The first parameter is the hotkey, the second is the function to call, and after that everything is passed to the function.
source share