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