Reputation: 14086
I would like to turn F15 into a macro key. Pressing another key while F15 is held should call a function that will read a .ini
file for instructions.
I know that I can it this like this, but I'd rather not have the giant list:
DoMacro(key) { ... }
F15 & a::DoMacro('a')
F15 & b::DoMacro('b')
F15 & c::DoMacro('c')
.
.
.
I tried fiddling around with Input
, but I couldn't figure out any way to capture (or even pass through) non-character keys. Is there any alternative to the long list?
Upvotes: 1
Views: 187
Reputation: 15488
Unfortunately there is no 100% nice way to do this in AHK (unless you know a way to do it through API calls which I don't).
I think the best you could make out of this situation is this:
GetAnyKey(timeout) {
Input, PressedKey, T%timeout% L1, {F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{F14}{F15}{F16}{F17}{F18}{F19}{F20}{F21}{F22}{F23}{F24}{PrintScreen}{Del}{Home}{End}{PgUp}{PgDn}{ScrollLock}{Pause}{Ins}{BS}{Space}{Left}{Right}{Up}{Down}{Left}{Right}{NumLock}{NumPad1}{NumPad2}{NumPad3}{NumPad4}{NumPad5}{NumPad6}{NumPad7}{NumPad8}{NumPad9}{NumPad0}{NumPadAdd}{NumPadSub}{NumPadMult}{NumPadDiv}{NumPadEnter}{NumPadDot}{NumPadEnd}{NumPadHome}{NumPadPgDn}{NumPadPgUp}{NumpadClear}{NumpadDown}{NumpadIns}{NumpadLeft}{NumpadRight}{AppsKey}{LShift}{RShift}{LCtrl}{RCtrl}{LAlt}{RAlt}{LWin}{RWin}
If (ErrorLevel = "Timeout")
Return
If PressedKey
Key := PressedKey
Else
Key := SubStr(ErrorLevel,8)
Return Key
}
F13::
Key := GetAnyKey(1)
If (Key && GetKeyState("F13", "P")) {
DoMacro(Key)
}
Return
DoMacro(Key) {
MsgBox, F13 and %Key% have been pressed!
}
I removed the hotkey (F13) from the Input key list, so that it doesn't trigger the Input when you wait too long.
So, if you change the hotkey you have to change the input list accordingly.
Upvotes: 1