The reason I ask this is because I have a script which makes WASD keys act as cursors, in the
Sherwood MMO, and I want it to toggle to act normally for chat.
At the moment I have it running as a separate script, and hotkey it to suspend. Which works OK, but I want to include it from a larger script, and suspend only this part.
Essentially, I want a #if... and the only AHK #if commands are #IfWinActive and #IfWinExist. These do not accept variables, because they're preprocessor things. They do accept WindowGroups, though.
WindowGroups COULD be used as a toggle, by adding/removing the relevant window from them... if windowGroups
could have entries removed from them - but though there's GroupAdd, there's no GroupRemove. Chris
writes:
Quote:
There's currently no way to do it, so the usual work-around would be to create a new group. Each group takes up very little memory, so that won't be a concern for most usages.
I tried to use a window as the "flag variable", like...
Code:
; Script Function:
; Example block-toggler (non-working)
; Enables the wasd keys in the Sherwood MMORPG. Toggle them on and
; off with ScrollLock, NumLock or PrintScreen.
; BUG:
; Does not turn off aliases when changing windows.
; License:
; This code is explicitly released to the public domain under the "code
; sample" precedent. You may modify, reuse or relicence it in any way
; without informing or attributing me. Truly free, not just "Free(tm)".
#AllowSameLineComments
#InstallKeybdHook
#NoEnv ; For security
#Persistent
#SingleInstance force
DetectHiddenWindows on
SendMode Input
return
#IfWinActive MMORPG in Sherwood
ScrollLock::
NumLock::
PrintScreen::
IfWinExist wasd2uldr
{
Gui destroy
}
else {
Gui, Add, Text,, Window for toggling the wasd2uldr block
Gui show, hide , wasd2uldr
DetectHiddenWindows on
}
return
#IfWinExist wasd2uldr
$*w::Send {up down}
$*w up::Send {up up}
$*a::Send {left down}
$*a up::Send {left up}
$*s::Send {down down}
$*s up::Send {down up}
$*d::Send {right down}
$*d up::Send {right up}
#IfWinExist
#IfWinActive
This ALMOST works... except that the #IfWinActive is overridden by the #IfWinExist. So alt-tabbing or moving away from the window while the wasd aliases are active would be really annoying.