ホーム › UI.Input.XboxController › XInputGetKeystroke
XInputGetKeystroke
関数Xboxコントローラーのキーストローク入力を取得する。
シグネチャ
// xinput1_4.dll
#include <windows.h>
DWORD XInputGetKeystroke(
DWORD dwUserIndex,
DWORD dwReserved, // optional
XINPUT_KEYSTROKE* pKeystroke
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dwUserIndex | DWORD | in | 対象コントローラーのインデックス(0〜3)を指定する。 |
| dwReserved | DWORD | optional | 予約済み。0を指定する。 |
| pKeystroke | XINPUT_KEYSTROKE* | out | キーストローク情報を受け取るXINPUT_KEYSTROKE構造体へのポインタ。 |
戻り値の型: 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 方式にも切替可。#uselib "xinput1_4.dll" #cfunc global XInputGetKeystroke "XInputGetKeystroke" int, int, sptr ; res = XInputGetKeystroke(dwUserIndex, dwReserved, varptr(pKeystroke)) ; dwUserIndex : DWORD -> "int" ; dwReserved : DWORD optional -> "int" ; pKeystroke : XINPUT_KEYSTROKE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; DWORD XInputGetKeystroke(DWORD dwUserIndex, DWORD dwReserved, XINPUT_KEYSTROKE* pKeystroke) #uselib "xinput1_4.dll" #cfunc global XInputGetKeystroke "XInputGetKeystroke" int, int, intptr ; res = XInputGetKeystroke(dwUserIndex, dwReserved, varptr(pKeystroke)) ; dwUserIndex : DWORD -> "int" ; dwReserved : DWORD optional -> "int" ; pKeystroke : XINPUT_KEYSTROKE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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)。const std = @import("std");
extern "xinput1_4" fn XInputGetKeystroke(
dwUserIndex: u32, // DWORD
dwReserved: u32, // DWORD optional
pKeystroke: [*c]XINPUT_KEYSTROKE // XINPUT_KEYSTROKE* out
) callconv(std.os.windows.WINAPI) u32;proc XInputGetKeystroke(
dwUserIndex: uint32, # DWORD
dwReserved: uint32, # DWORD optional
pKeystroke: ptr XINPUT_KEYSTROKE # XINPUT_KEYSTROKE* out
): uint32 {.importc: "XInputGetKeystroke", stdcall, dynlib: "xinput1_4.dll".}pragma(lib, "xinput1_4");
extern(Windows)
uint XInputGetKeystroke(
uint dwUserIndex, // DWORD
uint dwReserved, // DWORD optional
XINPUT_KEYSTROKE* pKeystroke // XINPUT_KEYSTROKE* out
);ccall((:XInputGetKeystroke, "xinput1_4.dll"), stdcall, UInt32,
(UInt32, UInt32, Ptr{XINPUT_KEYSTROKE}),
dwUserIndex, dwReserved, pKeystroke)
# dwUserIndex : DWORD -> UInt32
# dwReserved : DWORD optional -> UInt32
# pKeystroke : XINPUT_KEYSTROKE* out -> Ptr{XINPUT_KEYSTROKE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t XInputGetKeystroke(
uint32_t dwUserIndex,
uint32_t dwReserved,
void* pKeystroke);
]]
local xinput1_4 = ffi.load("xinput1_4")
-- xinput1_4.XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
-- dwUserIndex : DWORD
-- dwReserved : DWORD optional
-- pKeystroke : XINPUT_KEYSTROKE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('xinput1_4.dll');
const XInputGetKeystroke = lib.func('__stdcall', 'XInputGetKeystroke', 'uint32_t', ['uint32_t', 'uint32_t', 'void *']);
// XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
// dwUserIndex : DWORD -> 'uint32_t'
// dwReserved : DWORD optional -> 'uint32_t'
// pKeystroke : XINPUT_KEYSTROKE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("xinput1_4.dll", {
XInputGetKeystroke: { parameters: ["u32", "u32", "pointer"], result: "u32" },
});
// lib.symbols.XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke)
// dwUserIndex : DWORD -> "u32"
// dwReserved : DWORD optional -> "u32"
// pKeystroke : XINPUT_KEYSTROKE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t XInputGetKeystroke(
uint32_t dwUserIndex,
uint32_t dwReserved,
void* pKeystroke);
C, "xinput1_4.dll");
// $ffi->XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke);
// dwUserIndex : DWORD
// dwReserved : DWORD optional
// pKeystroke : XINPUT_KEYSTROKE* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Xinput1_4 extends StdCallLibrary {
Xinput1_4 INSTANCE = Native.load("xinput1_4", Xinput1_4.class);
int XInputGetKeystroke(
int dwUserIndex, // DWORD
int dwReserved, // DWORD optional
Pointer pKeystroke // XINPUT_KEYSTROKE* out
);
}@[Link("xinput1_4")]
lib Libxinput1_4
fun XInputGetKeystroke = XInputGetKeystroke(
dwUserIndex : UInt32, # DWORD
dwReserved : UInt32, # DWORD optional
pKeystroke : XINPUT_KEYSTROKE* # XINPUT_KEYSTROKE* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef XInputGetKeystrokeNative = Uint32 Function(Uint32, Uint32, Pointer<Void>);
typedef XInputGetKeystrokeDart = int Function(int, int, Pointer<Void>);
final XInputGetKeystroke = DynamicLibrary.open('xinput1_4.dll')
.lookupFunction<XInputGetKeystrokeNative, XInputGetKeystrokeDart>('XInputGetKeystroke');
// dwUserIndex : DWORD -> Uint32
// dwReserved : DWORD optional -> Uint32
// pKeystroke : XINPUT_KEYSTROKE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function XInputGetKeystroke(
dwUserIndex: DWORD; // DWORD
dwReserved: DWORD; // DWORD optional
pKeystroke: Pointer // XINPUT_KEYSTROKE* out
): DWORD; stdcall;
external 'xinput1_4.dll' name 'XInputGetKeystroke';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "XInputGetKeystroke"
c_XInputGetKeystroke :: Word32 -> Word32 -> Ptr () -> IO Word32
-- dwUserIndex : DWORD -> Word32
-- dwReserved : DWORD optional -> Word32
-- pKeystroke : XINPUT_KEYSTROKE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let xinputgetkeystroke =
foreign "XInputGetKeystroke"
(uint32_t @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* dwUserIndex : DWORD -> uint32_t *)
(* dwReserved : DWORD optional -> uint32_t *)
(* pKeystroke : XINPUT_KEYSTROKE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library xinput1_4 (t "xinput1_4.dll"))
(cffi:use-foreign-library xinput1_4)
(cffi:defcfun ("XInputGetKeystroke" xinput-get-keystroke :convention :stdcall) :uint32
(dw-user-index :uint32) ; DWORD
(dw-reserved :uint32) ; DWORD optional
(p-keystroke :pointer)) ; XINPUT_KEYSTROKE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $XInputGetKeystroke = Win32::API::More->new('xinput1_4',
'DWORD XInputGetKeystroke(DWORD dwUserIndex, DWORD dwReserved, LPVOID pKeystroke)');
# my $ret = $XInputGetKeystroke->Call($dwUserIndex, $dwReserved, $pKeystroke);
# dwUserIndex : DWORD -> DWORD
# dwReserved : DWORD optional -> DWORD
# pKeystroke : XINPUT_KEYSTROKE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型