ホーム › UI.Input.KeyboardAndMouse › GetKeyNameTextA
GetKeyNameTextA
関数スキャンコードに対応するキー名の文字列を取得する(ANSI版)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
INT GetKeyNameTextA(
INT lParam,
LPSTR lpString,
INT cchSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lParam | INT | in |
| lpString | LPSTR | out |
| cchSize | INT | in |
戻り値の型: INT
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
INT GetKeyNameTextA(
INT lParam,
LPSTR lpString,
INT cchSize
);[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern int GetKeyNameTextA(
int lParam, // INT
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpString, // LPSTR out
int cchSize // INT
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetKeyNameTextA(
lParam As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> lpString As System.Text.StringBuilder, ' LPSTR out
cchSize As Integer ' INT
) As Integer
End Function' lParam : INT
' lpString : LPSTR out
' cchSize : INT
Declare PtrSafe Function GetKeyNameTextA Lib "user32" ( _
ByVal lParam As Long, _
ByVal lpString As String, _
ByVal cchSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetKeyNameTextA = ctypes.windll.user32.GetKeyNameTextA
GetKeyNameTextA.restype = ctypes.c_int
GetKeyNameTextA.argtypes = [
ctypes.c_int, # lParam : INT
wintypes.LPSTR, # lpString : LPSTR out
ctypes.c_int, # cchSize : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetKeyNameTextA = Fiddle::Function.new(
lib['GetKeyNameTextA'],
[
Fiddle::TYPE_INT, # lParam : INT
Fiddle::TYPE_VOIDP, # lpString : LPSTR out
Fiddle::TYPE_INT, # cchSize : INT
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn GetKeyNameTextA(
lParam: i32, // INT
lpString: *mut u8, // LPSTR out
cchSize: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int GetKeyNameTextA(int lParam, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpString, int cchSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetKeyNameTextA' -Namespace Win32 -PassThru
# $api::GetKeyNameTextA(lParam, lpString, cchSize)#uselib "USER32.dll"
#func global GetKeyNameTextA "GetKeyNameTextA" sptr, sptr, sptr
; GetKeyNameTextA lParam, varptr(lpString), cchSize ; 戻り値は stat
; lParam : INT -> "sptr"
; lpString : LPSTR out -> "sptr"
; cchSize : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global GetKeyNameTextA "GetKeyNameTextA" int, var, int ; res = GetKeyNameTextA(lParam, lpString, cchSize) ; lParam : INT -> "int" ; lpString : LPSTR out -> "var" ; cchSize : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global GetKeyNameTextA "GetKeyNameTextA" int, sptr, int ; res = GetKeyNameTextA(lParam, varptr(lpString), cchSize) ; lParam : INT -> "int" ; lpString : LPSTR out -> "sptr" ; cchSize : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT GetKeyNameTextA(INT lParam, LPSTR lpString, INT cchSize) #uselib "USER32.dll" #cfunc global GetKeyNameTextA "GetKeyNameTextA" int, var, int ; res = GetKeyNameTextA(lParam, lpString, cchSize) ; lParam : INT -> "int" ; lpString : LPSTR out -> "var" ; cchSize : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT GetKeyNameTextA(INT lParam, LPSTR lpString, INT cchSize) #uselib "USER32.dll" #cfunc global GetKeyNameTextA "GetKeyNameTextA" int, intptr, int ; res = GetKeyNameTextA(lParam, varptr(lpString), cchSize) ; lParam : INT -> "int" ; lpString : LPSTR out -> "intptr" ; cchSize : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetKeyNameTextA = user32.NewProc("GetKeyNameTextA")
)
// lParam (INT), lpString (LPSTR out), cchSize (INT)
r1, _, err := procGetKeyNameTextA.Call(
uintptr(lParam),
uintptr(lpString),
uintptr(cchSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetKeyNameTextA(
lParam: Integer; // INT
lpString: PAnsiChar; // LPSTR out
cchSize: Integer // INT
): Integer; stdcall;
external 'USER32.dll' name 'GetKeyNameTextA';result := DllCall("USER32\GetKeyNameTextA"
, "Int", lParam ; INT
, "Ptr", lpString ; LPSTR out
, "Int", cchSize ; INT
, "Int") ; return: INT●GetKeyNameTextA(lParam, lpString, cchSize) = DLL("USER32.dll", "int GetKeyNameTextA(int, char*, int)")
# 呼び出し: GetKeyNameTextA(lParam, lpString, cchSize)
# lParam : INT -> "int"
# lpString : LPSTR out -> "char*"
# cchSize : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。