Win32 API 日本語リファレンス
ホームSystem.Console › SetConsoleKeyShortcuts

SetConsoleKeyShortcuts

関数
コンソールのキーボードショートカットを設定する内部関数。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

BOOL SetConsoleKeyShortcuts(
    BOOL bSet,
    BYTE bReserveKeys,
    APPKEY* lpAppKeys,
    DWORD dwNumAppKeys
);

パラメーター

名前方向
bSetBOOLin
bReserveKeysBYTEin
lpAppKeysAPPKEY*in
dwNumAppKeysDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetConsoleKeyShortcuts(
    BOOL bSet,
    BYTE bReserveKeys,
    APPKEY* lpAppKeys,
    DWORD dwNumAppKeys
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool SetConsoleKeyShortcuts(
    bool bSet,   // BOOL
    byte bReserveKeys,   // BYTE
    IntPtr lpAppKeys,   // APPKEY*
    uint dwNumAppKeys   // DWORD
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function SetConsoleKeyShortcuts(
    bSet As Boolean,   ' BOOL
    bReserveKeys As Byte,   ' BYTE
    lpAppKeys As IntPtr,   ' APPKEY*
    dwNumAppKeys As UInteger   ' DWORD
) As Boolean
End Function
' bSet : BOOL
' bReserveKeys : BYTE
' lpAppKeys : APPKEY*
' dwNumAppKeys : DWORD
Declare PtrSafe Function SetConsoleKeyShortcuts Lib "kernel32" ( _
    ByVal bSet As Long, _
    ByVal bReserveKeys As Byte, _
    ByVal lpAppKeys As LongPtr, _
    ByVal dwNumAppKeys As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetConsoleKeyShortcuts = ctypes.windll.kernel32.SetConsoleKeyShortcuts
SetConsoleKeyShortcuts.restype = wintypes.BOOL
SetConsoleKeyShortcuts.argtypes = [
    wintypes.BOOL,  # bSet : BOOL
    ctypes.c_ubyte,  # bReserveKeys : BYTE
    ctypes.c_void_p,  # lpAppKeys : APPKEY*
    wintypes.DWORD,  # dwNumAppKeys : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetConsoleKeyShortcuts = kernel32.NewProc("SetConsoleKeyShortcuts")
)

// bSet (BOOL), bReserveKeys (BYTE), lpAppKeys (APPKEY*), dwNumAppKeys (DWORD)
r1, _, err := procSetConsoleKeyShortcuts.Call(
	uintptr(bSet),
	uintptr(bReserveKeys),
	uintptr(lpAppKeys),
	uintptr(dwNumAppKeys),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetConsoleKeyShortcuts(
  bSet: BOOL;   // BOOL
  bReserveKeys: Byte;   // BYTE
  lpAppKeys: Pointer;   // APPKEY*
  dwNumAppKeys: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetConsoleKeyShortcuts';
result := DllCall("KERNEL32\SetConsoleKeyShortcuts"
    , "Int", bSet   ; BOOL
    , "UChar", bReserveKeys   ; BYTE
    , "Ptr", lpAppKeys   ; APPKEY*
    , "UInt", dwNumAppKeys   ; DWORD
    , "Int")   ; return: BOOL
●SetConsoleKeyShortcuts(bSet, bReserveKeys, lpAppKeys, dwNumAppKeys) = DLL("KERNEL32.dll", "bool SetConsoleKeyShortcuts(bool, byte, void*, dword)")
# 呼び出し: SetConsoleKeyShortcuts(bSet, bReserveKeys, lpAppKeys, dwNumAppKeys)
# bSet : BOOL -> "bool"
# bReserveKeys : BYTE -> "byte"
# lpAppKeys : APPKEY* -> "void*"
# dwNumAppKeys : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。