GetKeyState
提供: AutoHotkey Wiki
実行制御 | GUI表示 | 演算・変数 | メモリ・DLL操作 | 文字列操作 |
キーボード | マウス | シェル | ウィンドウ | ウィンドウグループ
ステータスバー | コントロール | サウンド | ファイル | INIファイル |
レジストリ | 環境変数 | AutoHotkey | その他 | 設定関係 | オブジェクト
GetKeyState[編集]
キーボードやマウスボタンの押し下げ状態、ジョイスティックの状態を取得。
GetKeyState, OutputVar, KeyName [, Mode]
Parameters[編集]
| 引数名 | 説明 | |
|---|---|---|
| OutputVar | 結果を格納する変数名。 取得に失敗したら、内容は空になる。 | |
| KeyName | 状態を取得したいキーの名称。 特殊キーの一覧はKey List参照。 | |
| Mode | この引数は省略可能で、ジョイスティックでは無効。 | |
| P | ソフトウェア的なキーボードイベント生成を無視し、実際にユーザーがキーを押しているかを取得できる。(NT系専用) (#InstallKeybdHook、#InstallMouseHookを記述するなどして、Hookを有効にしている必要あり) | |
| T | CapsLock, NumLock, ScrollLock のON/OFFの状態を取得できる。 この場合、ONなら D、OFFなら Uになる。
| |
Remarks[編集]
ボタンの場合、押し下げ状態なら D、押されてなければ UがOutputVarの変数に格納される。
ジョイスティックの軸(JoyXなど)の場合、0...100の間の小数で倒され具合が表される。(50なら倒されていない)(数値の書式はSetFormatで指定可能)
JoyPOVの場合、0...35900の値になる。正面を0とした角度を100倍したものになる模様。
Related[編集]
Key List, KeyHistory, #InstallKeybdHook, #InstallMouseHook, GetKeyState()
Example(s)[編集]
; Basic Examples:GetKeyState, state, Shift GetKeyState, state, CapsLock, T; D if CapsLock is ON or U otherwise.GetKeyState, state, RButton; Right mouse button.GetKeyState, state, Joy2; The second button of the first joystick.
; Advanced Example:; In this case, the mouse button is kept held down while NumpadAdd; is down, which effectively transforms NumpadAdd into a mouse button.; This method can also be used to repeat an action while the user is; holding down a key or button:NumpadAdd:: MouseClick, left, , , 1, 0, D; Hold down the left mouse button.Loop { Sleep, 10 GetKeyState, state, NumpadAdd, P If state = U; The key has been released, so break out of the loop.Break; ... insert here any other actions you want repeated.} MouseClick, left, , , 1, 0, U; Release the mouse button.Return; Example: Make joystick button behavior depend on joystick axis position.joy2:: GetKeyState, joyx, JoyX If joyx > 75 MsgBox Action #1 (button pressed while joystick was pushed to the right) Else If joyx < 25 MsgBox Action #2 (button pressed while joystick was pushed to the left) Else MsgBox Action #3 (button pressed while joystick was centered horizontally) Return