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