ホーム › UI.Input.KeyboardAndMouse › ToAsciiEx
ToAsciiEx
関数仮想キーとキー状態をASCII文字に変換する(レイアウト指定版)。
シグネチャ
// USER32.dll
#include <windows.h>
INT ToAsciiEx(
DWORD uVirtKey,
DWORD uScanCode,
const BYTE* lpKeyState, // optional
WORD* lpChar,
DWORD uFlags,
HKL dwhkl // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| uVirtKey | DWORD | in |
| uScanCode | DWORD | in |
| lpKeyState | BYTE* | inoptional |
| lpChar | WORD* | out |
| uFlags | DWORD | in |
| dwhkl | HKL | inoptional |
戻り値の型: INT
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
INT ToAsciiEx(
DWORD uVirtKey,
DWORD uScanCode,
const BYTE* lpKeyState, // optional
WORD* lpChar,
DWORD uFlags,
HKL dwhkl // optional
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern int ToAsciiEx(
uint uVirtKey, // DWORD
uint uScanCode, // DWORD
IntPtr lpKeyState, // BYTE* optional
out ushort lpChar, // WORD* out
uint uFlags, // DWORD
IntPtr dwhkl // HKL optional
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function ToAsciiEx(
uVirtKey As UInteger, ' DWORD
uScanCode As UInteger, ' DWORD
lpKeyState As IntPtr, ' BYTE* optional
<Out> ByRef lpChar As UShort, ' WORD* out
uFlags As UInteger, ' DWORD
dwhkl As IntPtr ' HKL optional
) As Integer
End Function' uVirtKey : DWORD
' uScanCode : DWORD
' lpKeyState : BYTE* optional
' lpChar : WORD* out
' uFlags : DWORD
' dwhkl : HKL optional
Declare PtrSafe Function ToAsciiEx Lib "user32" ( _
ByVal uVirtKey As Long, _
ByVal uScanCode As Long, _
ByVal lpKeyState As LongPtr, _
ByRef lpChar As Integer, _
ByVal uFlags As Long, _
ByVal dwhkl As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ToAsciiEx = ctypes.windll.user32.ToAsciiEx
ToAsciiEx.restype = ctypes.c_int
ToAsciiEx.argtypes = [
wintypes.DWORD, # uVirtKey : DWORD
wintypes.DWORD, # uScanCode : DWORD
ctypes.POINTER(ctypes.c_ubyte), # lpKeyState : BYTE* optional
ctypes.POINTER(ctypes.c_ushort), # lpChar : WORD* out
wintypes.DWORD, # uFlags : DWORD
wintypes.HANDLE, # dwhkl : HKL optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
ToAsciiEx = Fiddle::Function.new(
lib['ToAsciiEx'],
[
-Fiddle::TYPE_INT, # uVirtKey : DWORD
-Fiddle::TYPE_INT, # uScanCode : DWORD
Fiddle::TYPE_VOIDP, # lpKeyState : BYTE* optional
Fiddle::TYPE_VOIDP, # lpChar : WORD* out
-Fiddle::TYPE_INT, # uFlags : DWORD
Fiddle::TYPE_VOIDP, # dwhkl : HKL optional
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn ToAsciiEx(
uVirtKey: u32, // DWORD
uScanCode: u32, // DWORD
lpKeyState: *const u8, // BYTE* optional
lpChar: *mut u16, // WORD* out
uFlags: u32, // DWORD
dwhkl: *mut core::ffi::c_void // HKL optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern int ToAsciiEx(uint uVirtKey, uint uScanCode, IntPtr lpKeyState, out ushort lpChar, uint uFlags, IntPtr dwhkl);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ToAsciiEx' -Namespace Win32 -PassThru
# $api::ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, dwhkl)#uselib "USER32.dll"
#func global ToAsciiEx "ToAsciiEx" sptr, sptr, sptr, sptr, sptr, sptr
; ToAsciiEx uVirtKey, uScanCode, varptr(lpKeyState), varptr(lpChar), uFlags, dwhkl ; 戻り値は stat
; uVirtKey : DWORD -> "sptr"
; uScanCode : DWORD -> "sptr"
; lpKeyState : BYTE* optional -> "sptr"
; lpChar : WORD* out -> "sptr"
; uFlags : DWORD -> "sptr"
; dwhkl : HKL optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global ToAsciiEx "ToAsciiEx" int, int, var, var, int, sptr ; res = ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, dwhkl) ; uVirtKey : DWORD -> "int" ; uScanCode : DWORD -> "int" ; lpKeyState : BYTE* optional -> "var" ; lpChar : WORD* out -> "var" ; uFlags : DWORD -> "int" ; dwhkl : HKL optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global ToAsciiEx "ToAsciiEx" int, int, sptr, sptr, int, sptr ; res = ToAsciiEx(uVirtKey, uScanCode, varptr(lpKeyState), varptr(lpChar), uFlags, dwhkl) ; uVirtKey : DWORD -> "int" ; uScanCode : DWORD -> "int" ; lpKeyState : BYTE* optional -> "sptr" ; lpChar : WORD* out -> "sptr" ; uFlags : DWORD -> "int" ; dwhkl : HKL optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT ToAsciiEx(DWORD uVirtKey, DWORD uScanCode, BYTE* lpKeyState, WORD* lpChar, DWORD uFlags, HKL dwhkl) #uselib "USER32.dll" #cfunc global ToAsciiEx "ToAsciiEx" int, int, var, var, int, intptr ; res = ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, dwhkl) ; uVirtKey : DWORD -> "int" ; uScanCode : DWORD -> "int" ; lpKeyState : BYTE* optional -> "var" ; lpChar : WORD* out -> "var" ; uFlags : DWORD -> "int" ; dwhkl : HKL optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT ToAsciiEx(DWORD uVirtKey, DWORD uScanCode, BYTE* lpKeyState, WORD* lpChar, DWORD uFlags, HKL dwhkl) #uselib "USER32.dll" #cfunc global ToAsciiEx "ToAsciiEx" int, int, intptr, intptr, int, intptr ; res = ToAsciiEx(uVirtKey, uScanCode, varptr(lpKeyState), varptr(lpChar), uFlags, dwhkl) ; uVirtKey : DWORD -> "int" ; uScanCode : DWORD -> "int" ; lpKeyState : BYTE* optional -> "intptr" ; lpChar : WORD* out -> "intptr" ; uFlags : DWORD -> "int" ; dwhkl : HKL optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procToAsciiEx = user32.NewProc("ToAsciiEx")
)
// uVirtKey (DWORD), uScanCode (DWORD), lpKeyState (BYTE* optional), lpChar (WORD* out), uFlags (DWORD), dwhkl (HKL optional)
r1, _, err := procToAsciiEx.Call(
uintptr(uVirtKey),
uintptr(uScanCode),
uintptr(lpKeyState),
uintptr(lpChar),
uintptr(uFlags),
uintptr(dwhkl),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction ToAsciiEx(
uVirtKey: DWORD; // DWORD
uScanCode: DWORD; // DWORD
lpKeyState: Pointer; // BYTE* optional
lpChar: Pointer; // WORD* out
uFlags: DWORD; // DWORD
dwhkl: THandle // HKL optional
): Integer; stdcall;
external 'USER32.dll' name 'ToAsciiEx';result := DllCall("USER32\ToAsciiEx"
, "UInt", uVirtKey ; DWORD
, "UInt", uScanCode ; DWORD
, "Ptr", lpKeyState ; BYTE* optional
, "Ptr", lpChar ; WORD* out
, "UInt", uFlags ; DWORD
, "Ptr", dwhkl ; HKL optional
, "Int") ; return: INT●ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, dwhkl) = DLL("USER32.dll", "int ToAsciiEx(dword, dword, void*, void*, dword, void*)")
# 呼び出し: ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, dwhkl)
# uVirtKey : DWORD -> "dword"
# uScanCode : DWORD -> "dword"
# lpKeyState : BYTE* optional -> "void*"
# lpChar : WORD* out -> "void*"
# uFlags : DWORD -> "dword"
# dwhkl : HKL optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。