KeyWait
提供: AutoHotkey Wiki
実行制御 | GUI表示 | 演算・変数 | メモリ・DLL操作 | 文字列操作 |
キーボード | マウス | シェル | ウィンドウ | ウィンドウグループ
ステータスバー | コントロール | サウンド | ファイル | INIファイル |
レジストリ | 環境変数 | AutoHotkey | その他 | 設定関係 | オブジェクト
KeyWait[編集]
キーボードやマウス、ジョイスティックのボタンが押される/離されるまで待機。
KeyWait, KeyName [, Options]
Parameters[編集]
引数名 | 説明 | |
---|---|---|
KeyName | 文字キーの文字やキーリストにあるキー名。 ジョイスティックのJoy1...Joy32以外の要素は使用出来ない。 | |
Options | 以下のものを半角スペース区切りで指定。 | |
D | 押し下げられるのを待つ(通常は離されるのを待つ) | |
L | 強制的に論理的判定を使用 | |
Tn | n に待機する最大秒数を指定(例:T3 )。小数も指定可能。
|
ErrorLevel[編集]
Tオプションで指定した秒数が経過した場合 1
、それ以外は 0
Remarks[編集]
Optionsが何も指定されなかった場合、指定したキーが離されるまでずっと待機し続ける。
WindowsNT系でキーボード/マウスフックが使用されている場合、物理的なキー/ボタンの状態(ユーザーが実際にキー/ボタンを押しているか)によって判定される。
#InstallKeybdHookや#InstallMouseHook指令で、強制的にフックを有効にすることが可能。
上記の条件に当てはまらない場合、論理的な状態で判定される。
この場合、AutoHotkeyのSendコマンドのようなプログラムによって生成された操作にも反応してしまう。
待機中はホットキーやタイマーなどで起動されたスレッドが割り込める。
複数のキーが指定の状態になるのを待たせたい場合は、複数のKeyWaitを連続して実行すればよい
KeyWait,Control KeyWait,Alt
複数のキーのうちのどれかが押されるのを待ちたい場合は、Inputコマンドを使う。
Related[編集]
キーリスト, GetKeyState, Input, KeyHistory, #InstallKeybdHook, #InstallMouseHook, ClipWait, WinWait
Example(s)[編集]
KeyWait, a; Wait for the A key to be released.
KeyWait, LButton, D; Wait for the left mouse button to be pressed down.
KeyWait, Joy1, D T3; Wait up to 3 seconds for the first joystick button to be pressed down.
KeyWait, LAlt, L; Wait for the left-alt key to be logically released.
; Hotkey example:
~Capslock:: KeyWait, Capslock; Wait for user to physically release it.
MsgBox You pressed and released the Capslock key. Return
; Remapping example:
; The left mouse button is kept held down while NumpadAdd is down,
; which effectively transforms NumpadAdd into the left mouse button.
*NumpadAdd:: MouseClick, left,,, 1, 0, D; Hold down the left mouse button.
KeyWait, NumpadAdd; Wait for the key to be released.
MouseClick, left,,, 1, 0, U; Release the mouse button.
Return
; This example shows how to detect when a key has been double-pressed (similar to double-click):
; It relies on #MaxThreadsPerHotkey being at its default setting of 1.
~RControl:: If A_PriorHotkey <> ~RControl { KeyWait, RControl Return } If A_TimeSincePriorHotkey > 400; Too much time between presses, so this isn't a double-press.
{ KeyWait, RControl Return } MsgBox You double-pressed the right control key. Return