ホーム › UI.Input.KeyboardAndMouse › GetKeyState
GetKeyState
関数指定した仮想キーの押下・トグル状態を取得する。
シグネチャ
// USER32.dll
#include <windows.h>
SHORT GetKeyState(
INT nVirtKey
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| nVirtKey | INT | in |
戻り値の型: SHORT
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
SHORT GetKeyState(
INT nVirtKey
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern short GetKeyState(
int nVirtKey // INT
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function GetKeyState(
nVirtKey As Integer ' INT
) As Short
End Function' nVirtKey : INT
Declare PtrSafe Function GetKeyState Lib "user32" ( _
ByVal nVirtKey As Long) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetKeyState = ctypes.windll.user32.GetKeyState
GetKeyState.restype = ctypes.c_short
GetKeyState.argtypes = [
ctypes.c_int, # nVirtKey : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetKeyState = Fiddle::Function.new(
lib['GetKeyState'],
[
Fiddle::TYPE_INT, # nVirtKey : INT
],
Fiddle::TYPE_SHORT)#[link(name = "user32")]
extern "system" {
fn GetKeyState(
nVirtKey: i32 // INT
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern short GetKeyState(int nVirtKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetKeyState' -Namespace Win32 -PassThru
# $api::GetKeyState(nVirtKey)#uselib "USER32.dll"
#func global GetKeyState "GetKeyState" sptr
; GetKeyState nVirtKey ; 戻り値は stat
; nVirtKey : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global GetKeyState "GetKeyState" int
; res = GetKeyState(nVirtKey)
; nVirtKey : INT -> "int"; SHORT GetKeyState(INT nVirtKey)
#uselib "USER32.dll"
#cfunc global GetKeyState "GetKeyState" int
; res = GetKeyState(nVirtKey)
; nVirtKey : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetKeyState = user32.NewProc("GetKeyState")
)
// nVirtKey (INT)
r1, _, err := procGetKeyState.Call(
uintptr(nVirtKey),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction GetKeyState(
nVirtKey: Integer // INT
): Smallint; stdcall;
external 'USER32.dll' name 'GetKeyState';result := DllCall("USER32\GetKeyState"
, "Int", nVirtKey ; INT
, "Short") ; return: SHORT●GetKeyState(nVirtKey) = DLL("USER32.dll", "int GetKeyState(int)")
# 呼び出し: GetKeyState(nVirtKey)
# nVirtKey : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。