キーボードやマウスボタンの押し下げ状態、ジョイスティックの状態を取得
GetKeyState, OutputVar, KeyName [, Mode]
| 引数名 | 説明 |
|---|---|
| OutputVar |
結果を格納する変数名。 取得に失敗したら、内容は空になる。 |
| KeyName | 状態を取得したいキーの名称。 特殊キーの一覧はKey List参照。 |
| Mode |
「P」を指定すると、ソフトウェア的なキーボードイベント生成を無視し、実際にユーザーがキーを押しているかを取得できる。(NT系専用)(#InstallKeybdHook、#InstallMouseHookを記述するなどして、Hookを有効にしている必要あり) 「T」を指定すると、CapsLock,NumLock,ScrollLockのON/OFFの状態を取得できる。 この場合、ONなら「D」、OFFなら「U」になる。 この引数は省略可能で、ジョイスティックでは無効。 |
ボタンの場合、押し下げ状態なら「D」、押されてなければ「U」がOutputVarの変数に格納される。
ジョイスティックの軸(JoyXなど)の場合、0...100の間の小数で倒され具合が表される。(50なら倒されていない)(数値の書式はSetFormatで指定可能)
JoyPOVの場合、0...35900の値になる。正面を0とした角度を100倍したものになる模様。
Key List, KeyHistory, #InstallKeybdHook, #InstallMouseHook, GetKeyState()
; 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