Win32 API 日本語リファレンス
ホームUI.Input.KeyboardAndMouse › VkKeyScanW

VkKeyScanW

関数
文字を対応する仮想キーとシフト状態に変換する(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

SHORT VkKeyScanW(
    WCHAR ch
);

パラメーター

名前方向
chWCHARin

戻り値の型: SHORT

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

SHORT VkKeyScanW(
    WCHAR ch
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short VkKeyScanW(
    char ch   // WCHAR
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function VkKeyScanW(
    ch As Char   ' WCHAR
) As Short
End Function
' ch : WCHAR
Declare PtrSafe Function VkKeyScanW Lib "user32" ( _
    ByVal ch As Integer) As Integer
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

VkKeyScanW = ctypes.windll.user32.VkKeyScanW
VkKeyScanW.restype = ctypes.c_short
VkKeyScanW.argtypes = [
    ctypes.c_wchar,  # ch : WCHAR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
VkKeyScanW = Fiddle::Function.new(
  lib['VkKeyScanW'],
  [
    Fiddle::TYPE_SHORT,  # ch : WCHAR
  ],
  Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn VkKeyScanW(
        ch: u16  // WCHAR
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern short VkKeyScanW(char ch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_VkKeyScanW' -Namespace Win32 -PassThru
# $api::VkKeyScanW(ch)
#uselib "USER32.dll"
#func global VkKeyScanW "VkKeyScanW" wptr
; VkKeyScanW ch   ; 戻り値は stat
; ch : WCHAR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global VkKeyScanW "VkKeyScanW" int
; res = VkKeyScanW(ch)
; ch : WCHAR -> "int"
; SHORT VkKeyScanW(WCHAR ch)
#uselib "USER32.dll"
#cfunc global VkKeyScanW "VkKeyScanW" int
; res = VkKeyScanW(ch)
; ch : WCHAR -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procVkKeyScanW = user32.NewProc("VkKeyScanW")
)

// ch (WCHAR)
r1, _, err := procVkKeyScanW.Call(
	uintptr(ch),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function VkKeyScanW(
  ch: WideChar   // WCHAR
): Smallint; stdcall;
  external 'USER32.dll' name 'VkKeyScanW';
result := DllCall("USER32\VkKeyScanW"
    , "Short", ch   ; WCHAR
    , "Short")   ; return: SHORT
●VkKeyScanW(ch) = DLL("USER32.dll", "int VkKeyScanW(int)")
# 呼び出し: VkKeyScanW(ch)
# ch : WCHAR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。