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

XInputGetKeystroke

関数
Xboxコントローラーのキーストローク入力を取得する。
DLLxinput1_4.dll呼出規約winapi

シグネチャ

// xinput1_4.dll
#include <windows.h>

DWORD XInputGetKeystroke(
    DWORD dwUserIndex,
    DWORD dwReserved,   // optional
    XINPUT_KEYSTROKE* pKeystroke
);

パラメーター

名前方向
dwUserIndexDWORDin
dwReservedDWORDoptional
pKeystrokeXINPUT_KEYSTROKE*out

戻り値の型: DWORD

各言語での呼び出し定義

// xinput1_4.dll
#include <windows.h>

DWORD XInputGetKeystroke(
    DWORD dwUserIndex,
    DWORD dwReserved,   // optional
    XINPUT_KEYSTROKE* pKeystroke
);
[DllImport("xinput1_4.dll", ExactSpelling = true)]
static extern uint XInputGetKeystroke(
    uint dwUserIndex,   // DWORD
    uint dwReserved,   // DWORD optional
    IntPtr pKeystroke   // XINPUT_KEYSTROKE* out
);
<DllImport("xinput1_4.dll", ExactSpelling:=True)>
Public Shared Function XInputGetKeystroke(
    dwUserIndex As UInteger,   ' DWORD
    dwReserved As UInteger,   ' DWORD optional
    pKeystroke As IntPtr   ' XINPUT_KEYSTROKE* out
) As UInteger
End Function
' dwUserIndex : DWORD
' dwReserved : DWORD optional
' pKeystroke : XINPUT_KEYSTROKE* out
Declare PtrSafe Function XInputGetKeystroke Lib "xinput1_4" ( _
    ByVal dwUserIndex As Long, _
    ByVal dwReserved As Long, _
    ByVal pKeystroke As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

XInputGetKeystroke = ctypes.windll.xinput1_4.XInputGetKeystroke
XInputGetKeystroke.restype = wintypes.DWORD
XInputGetKeystroke.argtypes = [
    wintypes.DWORD,  # dwUserIndex : DWORD
    wintypes.DWORD,  # dwReserved : DWORD optional
    ctypes.c_void_p,  # pKeystroke : XINPUT_KEYSTROKE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('xinput1_4.dll')
XInputGetKeystroke = Fiddle::Function.new(
  lib['XInputGetKeystroke'],
  [
    -Fiddle::TYPE_INT,  # dwUserIndex : DWORD
    -Fiddle::TYPE_INT,  # dwReserved : DWORD optional
    Fiddle::TYPE_VOIDP,  # pKeystroke : XINPUT_KEYSTROKE* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "xinput1_4")]
extern "system" {
    fn XInputGetKeystroke(
        dwUserIndex: u32,  // DWORD
        dwReserved: u32,  // DWORD optional
        pKeystroke: *mut XINPUT_KEYSTROKE  // XINPUT_KEYSTROKE* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("xinput1_4.dll")]
public static extern uint XInputGetKeystroke(uint dwUserIndex, uint dwReserved, IntPtr pKeystroke);
"@
$api = Add-Type -MemberDefinition $sig -Name 'xinput1_4_XInputGetKeystroke' -Namespace Win32 -PassThru
# $api::XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
#uselib "xinput1_4.dll"
#func global XInputGetKeystroke "XInputGetKeystroke" sptr, sptr, sptr
; XInputGetKeystroke dwUserIndex, dwReserved, varptr(pKeystroke)   ; 戻り値は stat
; dwUserIndex : DWORD -> "sptr"
; dwReserved : DWORD optional -> "sptr"
; pKeystroke : XINPUT_KEYSTROKE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "xinput1_4.dll"
#cfunc global XInputGetKeystroke "XInputGetKeystroke" int, int, var
; res = XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
; dwUserIndex : DWORD -> "int"
; dwReserved : DWORD optional -> "int"
; pKeystroke : XINPUT_KEYSTROKE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD XInputGetKeystroke(DWORD dwUserIndex, DWORD dwReserved, XINPUT_KEYSTROKE* pKeystroke)
#uselib "xinput1_4.dll"
#cfunc global XInputGetKeystroke "XInputGetKeystroke" int, int, var
; res = XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
; dwUserIndex : DWORD -> "int"
; dwReserved : DWORD optional -> "int"
; pKeystroke : XINPUT_KEYSTROKE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	xinput1_4 = windows.NewLazySystemDLL("xinput1_4.dll")
	procXInputGetKeystroke = xinput1_4.NewProc("XInputGetKeystroke")
)

// dwUserIndex (DWORD), dwReserved (DWORD optional), pKeystroke (XINPUT_KEYSTROKE* out)
r1, _, err := procXInputGetKeystroke.Call(
	uintptr(dwUserIndex),
	uintptr(dwReserved),
	uintptr(pKeystroke),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function XInputGetKeystroke(
  dwUserIndex: DWORD;   // DWORD
  dwReserved: DWORD;   // DWORD optional
  pKeystroke: Pointer   // XINPUT_KEYSTROKE* out
): DWORD; stdcall;
  external 'xinput1_4.dll' name 'XInputGetKeystroke';
result := DllCall("xinput1_4\XInputGetKeystroke"
    , "UInt", dwUserIndex   ; DWORD
    , "UInt", dwReserved   ; DWORD optional
    , "Ptr", pKeystroke   ; XINPUT_KEYSTROKE* out
    , "UInt")   ; return: DWORD
●XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke) = DLL("xinput1_4.dll", "dword XInputGetKeystroke(dword, dword, void*)")
# 呼び出し: XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
# dwUserIndex : DWORD -> "dword"
# dwReserved : DWORD optional -> "dword"
# pKeystroke : XINPUT_KEYSTROKE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。