Specifies the criteria for subsequently created or modified hotkey variants and hotstring variants.
HotIf "Expression" HotIf Callback
型:文字列
If omitted, blank criteria will be set (turns off context-sensitivity). Otherwise, the criteria will be set to an existing #HotIf expression. The expression is usually written as a quoted string, but can also be a variable or expression which returns text matching a #HotIf expression.
注意:HotIf関数は、元のソースコードではなく、渡した文字列を使用します。エスケープシーケンスはスクリプトのロード時に解決されるため、結果の文字のみが考慮されます。例えば、HotIf 'x = "`t"'
とHotIf 'x = "' A_Tab '"'
はどちらも#HotIf x = "`t"
に相当します。
For an example, see #HotIf example #5.
型:機能オブジェクト
If omitted, blank criteria will be set (turns off context-sensitivity). Otherwise, the criteria will be set to a given function object. Subsequently-created hotkeys and hotstrings will only execute if the callback returns a non-zero number. This is like HotIf "Expression"
, except that each hotkey and hotstring can have many hotkey variants or hotstring variants (one per object).
The callback accepts one parameter and can be defined as follows:
MyCallback(HotkeyName) { ...
Although the name you give the parameter does not matter, it is assigned the hotkey name or hotstring name.
You can omit the callback's parameter if the corresponding information is not needed, but in this case an asterisk must be specified, e.g. MyCallback(*)
.
HotIf関数に渡されたオブジェクトは削除されることはありません(ただし、プロセス終了時にOSによってメモリが回収されます)。
For an example, see example #2 below or Hotkey example #6.
HotIfWinActive WinTitle, WinText HotIfWinExist WinTitle, WinText HotIfWinNotActive WinTitle, WinText HotIfWinNotExist WinTitle, WinText
型:文字列
If both are omitted, blank criteria will be set (turns off context-sensitivity). そうでないときは、WinTitleに ウィンドウタイトルまたはターゲットウィンドウを識別するための他の基準、および/またはWinTextにターゲットウィンドウの単一のテキスト要素からの部分文字列(付属のWindow Spyユーティリティを使えばわかります)を指定します。Depending on which function is called, affected hotkeys and hotstrings are in effect only while the target window is active, exists, is not active, or does not exist.
パラメータは関数が呼び出される前に評価されるため、変数への参照はその時点で永続的なものとなります。In other words, subsequent changes to the contents of the variable are not seen by existing hotkeys and hotstrings.
WinTitle、WinTextは、WinActive、WinExistと同じ意味ですが、文字列のみ使用でき、自動実行スレッドが設定したSetTitleMatchMode、DetectHiddenWindowsのデフォルト設定に従って評価されます。
For an example, see example #1 below.
An exception is thrown if HotIf's parameter is invalid, such as if it does not match an existing expression or is not a valid callback function.
The HotIf and HotIfWin functions allow context-sensitive hotkeys and hotstrings to be created and modified while the script is running (by contrast, the #HotIf directive is positional and takes effect before the script begins executing). 事例:
HotIfWinActive "ahk_class Notepad" Hotkey "^!e", MyFuncForNotepad ; メモ帳でのみ動作するホットキーを作成します。
Using HotIf or one of the HotIfWin functions puts context sensitivity into effect for all subsequently created hotkeys and hotstrings in the current thread, and affects which hotkey variants the Hotkey function modifies and which hotstring variants the Hotstring function modifies. Only the most recent call to the HotIf or HotIfWin function in the current thread will be in effect.
To turn off context sensitivity (such as to make subsequently-created hotkeys and hotstrings work in all windows), call HotIf or one of the HotIfWin functions but omit the parameters. 事例:HotIf
または HotIfWinActive
。
Before HotIf or one of the HotIfWin functions is used in a hotkey or hotstring thread, the Hotkey and Hotstring functions default to the same context as the hotkey or hotstring that launched the thread. つまり、Hotkey A_ThisHotkey, "Off "
は、現在のホットキーがコンテキストセンシティブであってもオフします。All other threads default to creating or modifying global hotkeys and hotstrings, unless that default is overridden by using HotIf or one of the HotIfWin functions during script startup.
When a mouse or keyboard hotkey is disabled via HotIf, one of the HotIfWin functions, or the #HotIf directive, it performs its native function; that is, it passes through to the active window as though there is no such hotkey. However, controller hotkeys always pass through, whether they are disabled or not.
ホットキー、ホットストリング、Hotkey関数、Hotstring関数、#HotIf、スレッド
Similar to #HotIf example #1, this creates two hotkeys and one hotstring which only work when Notepad is active, and one hotkey which works for any window except Notepad. The main difference is that this example creates context-sensitive hotkeys and hotstrings at runtime, while the #HotIf example creates them at loadtime.
HotIfWinActive "ahk_class Notepad" Hotkey "^!a", ShowMsgBox Hotkey "#c", ShowMsgBox Hotstring "::btw", "This replacement text will occur only in Notepad." HotIfWinActive Hotkey "#c", (*) => MsgBox("You pressed Win-C in a window other than Notepad.") ShowMsgBox(HotkeyName) { MsgBox "You pressed " HotkeyName " while Notepad is active." }
Similar to the example above, but with a callback.
HotIf MyCallback Hotkey "^!a", ShowMsgBox Hotkey "#c", ShowMsgBox Hotstring "::btw", "This replacement text will occur only in Notepad." HotIf Hotkey "#c", (*) => MsgBox("You pressed Win-C in a window other than Notepad.") MyCallback(*) { if WinActive("ahk_class Notepad") return true else return false } ShowMsgBox(HotkeyName) { MsgBox "You pressed " HotkeyName " while Notepad is active." }