ReactOS 0.4.17-dev-1321-g5c122a9
kbd.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS SDK
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Keyboard layout definitions
5 * COPYRIGHT: Copyright 2003 James Tabor
6 * Copyright 2011 Rafal Harabien
7 * Copyright 2026 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
8 */
9
10#ifndef __KBD_H
11#define __KBD_H
12#pragma once
13
14/* ------------------------------------------------------------------ */
15/* Pointer slots inside the layout tables */
16/* */
17/* Native layout : slots are ordinary pointers. */
18/* WOW64 layout : (BUILD_WOW6432, 32-bit image) every pointer slot */
19/* is 64 bits wide, as in the Windows DDK kbd.h. */
20/* */
21/* KBD_PTR(T) declares a table pointer slot of type T. */
22/* MSVC / clang-cl : T __ptr64 */
23/* GCC / clang : __ptr64 does not exist, so the slot is a */
24/* 8-byte aligned union whose first member is the */
25/* pointer. Because the first member of a union */
26/* takes the initializer (C99 6.7.8p20) and the */
27/* remaining bytes of a static object are zero, */
28/* table sources such as */
29/* { aVkToBits, 7, {...} } */
30/* compile unchanged and the upper 32 bits of the */
31/* slot are 0. This relies on little endian (x86).*/
32/* Code that *reads* a table built this way must */
33/* use ->p; only layout DLLs are built like this. */
34#if defined(BUILD_WOW6432) && !defined(_WIN64)
35# if defined(_MSC_VER)
36# define KBD_LONG_POINTER __ptr64
37# define KBD_PTR(T) T KBD_LONG_POINTER
38# else
39# if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
40# error "WOW64 keyboard tables without __ptr64 require a little-endian target"
41# endif
42# define KBD_LONG_POINTER
43# define KBD_PTR(T) union { T p; ULONG64 u64; } __attribute__((aligned(8)))
44# define KBD_PTR_IS_UNION 1
45# pragma GCC diagnostic ignored "-Wmissing-braces" /* brace elision is intended */
46# endif
47#else
48# define KBD_LONG_POINTER
49# define KBD_PTR(T) T
50#endif
51
52#ifdef KBD_PTR_IS_UNION
53# define KBD_P(x) ((x).p)
54#else
55# define KBD_P(x) (x)
56#endif
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
62/* Virtual key flags */
63#define KBDEXT 0x100 /* Extended key code */
64#define KBDMULTIVK 0x200 /* Multi-key */
65#define KBDSPECIAL 0x400 /* Special key */
66#define KBDNUMPAD 0x800 /* Number-pad */
67
68/* Modifier bits */
69#define KBDSHIFT 0x001 /* Shift modifier */
70#define KBDCTRL 0x002 /* Ctrl modifier */
71#define KBDALT 0x004 /* Alt modifier */
72
73/* Invalid shift */
74#define SHFT_INVALID 0x0F
75
76 typedef struct _VK_TO_BIT {
80
81 typedef struct _MODIFIERS {
86
87#define TYPEDEF_VK_TO_WCHARS(i) \
88 typedef struct _VK_TO_WCHARS ## i { \
89 BYTE VirtualKey; \
90 BYTE Attributes; \
91 WCHAR wch[i]; \
92 } VK_TO_WCHARS ## i, *PVK_TO_WCHARS ## i;
93
104
106 KBD_PTR(PVK_TO_WCHARS1) pVkToWchars;
110
111 typedef struct _DEADKEY {
116
117 /* One slot of the dead-key name array (pKeyNamesDead points at these) */
118 typedef KBD_PTR(LPWSTR) DEADKEY_LPWSTR;
119
120#define DKF_DEAD 1
121
122 typedef struct _VSC_LPWSTR {
126
127 typedef struct _VSC_VK {
131
132#define TYPEDEF_LIGATURE(i) \
133typedef struct _LIGATURE ## i { \
134 BYTE VirtualKey; \
135 WORD ModificationNumber; \
136 WCHAR wch[i]; \
137} LIGATURE ## i, *PLIGATURE ## i;
138
144
145#define KBD_VERSION 1
146#define GET_KBD_VERSION(p) (HIWORD((p)->fLocaleFlags))
147#define KLLF_ALTGR 0x1
148#define KLLF_SHIFTLOCK 0x2
149#define KLLF_LRM_RLM 0x4
150
151 typedef struct _KBDTABLES {
152 KBD_PTR(PMODIFIERS) pCharModifiers;
153 KBD_PTR(PVK_TO_WCHAR_TABLE) pVkToWcharTable;
154 KBD_PTR(PDEADKEY) pDeadKey;
155 KBD_PTR(VSC_LPWSTR *) pKeyNames;
156 KBD_PTR(VSC_LPWSTR *) pKeyNamesExt;
157 KBD_PTR(DEADKEY_LPWSTR *) pKeyNamesDead;
158 KBD_PTR(USHORT *) pusVSCtoVK;
160 KBD_PTR(PVSC_VK) pVSCtoVK_E0;
161 KBD_PTR(PVSC_VK) pVSCtoVK_E1;
165 KBD_PTR(PLIGATURE1) pLigature;
167
168/* Constants that help table decoding */
169#define WCH_NONE 0xf000
170#define WCH_DEAD 0xf001
171#define WCH_LGTR 0xf002
172
173/* VK_TO_WCHARS attributes */
174#define CAPLOK 0x01
175#define SGCAPS 0x02
176#define CAPLOKALTGR 0x04
177#define KANALOK 0x08
178#define GRPSELTAP 0x80
179
180#define VK_ABNT_C1 0xC1
181#define VK_ABNT_C2 0xC2
182
183/* Useful scancodes */
184#define SCANCODE_LSHIFT 0x2A
185#define SCANCODE_RSHIFT 0x36
186#define SCANCODE_CTRL 0x1D
187#define SCANCODE_ALT 0x38
188
189/* ------------------------------------------------------------------ */
190/* Multi-table definitions */
191
192typedef struct tagKBDTABLE_DESC
193{
198
199#define KBDTABLE_MULTI_MAX 8
200
201typedef struct tagKBDTABLE_MULTI
202{
206
207/* ------------------------------------------------------------------ */
208/* NLS (Far-East) definitions */
209
210#define KBDNLS_TYPE_NULL 0
211#define KBDNLS_TYPE_NORMAL 1
212#define KBDNLS_TYPE_TOGGLE 2
213
214#define KBDNLS_INDEX_NORMAL 1
215#define KBDNLS_INDEX_ALT 2
216
217/* NLSFEProcIndex values */
218#define KBDNLS_NULL 0 /* invalid */
219#define KBDNLS_NOEVENT 1 /* swallow the key */
220#define KBDNLS_SEND_BASE_VK 2 /* send the base VK */
221#define KBDNLS_SEND_PARAM_VK 3 /* send the VK in the parameter */
222#define KBDNLS_KANALOCK 4
223#define KBDNLS_ALPHANUM 5
224#define KBDNLS_HIRAGANA 6
225#define KBDNLS_KATAKANA 7
226#define KBDNLS_SBCSDBCS 8
227#define KBDNLS_ROMAN 9
228#define KBDNLS_CODEINPUT 10
229#define KBDNLS_HELP_OR_END 11
230#define KBDNLS_HOME_OR_CLEAR 12
231#define KBDNLS_NUMPAD 13
232#define KBDNLS_KANAEVENT 14
233#define KBDNLS_CONV_OR_NONCONV 15
234
235typedef struct _VK_FUNCTION_PARAM
236{
240
242{
250
251typedef struct tagKbdNlsLayer
252{
256 KBD_PTR(PVK_F) pVkToF;
258 KBD_PTR(PUSHORT) pusMouseVKey;
260
261/* KBDTABLES as used by the FE layouts: dwType/dwSubType follow pLigature */
262typedef struct tagKBDTABLES_FE
263{
268
269/* ------------------------------------------------------------------ */
270/* Layout self-checks: the WOW64 layout must equal the x64 layout. */
271#if defined(BUILD_WOW6432) && defined(C_ASSERT)
272C_ASSERT(sizeof(MODIFIERS) == 16);
273C_ASSERT(sizeof(VK_TO_WCHAR_TABLE) == 16);
274C_ASSERT(sizeof(VSC_LPWSTR) == 16);
275C_ASSERT(sizeof(DEADKEY_LPWSTR) == 8);
276C_ASSERT(sizeof(KBDTABLES) == 96);
277C_ASSERT(sizeof(KBDNLSTABLES) == 32);
278#endif
279
280#if (NTDDI_VERSION >= NTDDI_WINXP)
281#define VK_DBE_ALPHANUMERIC 0xF0
282#define VK_DBE_KATAKANA 0xF1
283#define VK_DBE_HIRAGANA 0xF2
284#define VK_DBE_SBCSCHAR 0xF3
285#define VK_DBE_DBCSCHAR 0xF4
286#define VK_DBE_ROMAN 0xF5
287#define VK_DBE_NOROMAN 0xF6
288#define VK_DBE_ENTERWORDREGISTERMODE 0xF7
289#define VK_DBE_ENTERIMECONFIGMODE 0xF8
290#define VK_DBE_FLUSHSTRING 0xF9
291#define VK_DBE_CODEINPUT 0xFA
292#define VK_DBE_NOCODEINPUT 0xFB
293#define VK_DBE_DETERMINESTRING 0xFC
294#define VK_DBE_ENTERDLGCONVERSIONMODE 0xFD
295#endif // (NTDDI_VERSION >= NTDDI_WINXP)
296
297#ifdef __cplusplus
298} // extern "C"
299#endif
300
301#endif /* __KBD_H */
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int UINT
Definition: sysinfo.c:13
#define C_ASSERT(e)
Definition: intsafe.h:73
struct _VSC_LPWSTR * PVSC_LPWSTR
struct _VK_TO_WCHAR_TABLE VK_TO_WCHAR_TABLE
struct _VK_TO_BIT VK_TO_BIT
struct tagKBDTABLE_DESC * PKBDTABLE_DESC
struct _VK_TO_FUNCTION_TABLE VK_F
struct tagKBDTABLE_MULTI * PKBDTABLE_MULTI
struct _KBDTABLES * PKBDTABLES
struct _DEADKEY * PDEADKEY
struct tagKBDTABLES_FE KBDTABLES_FE
struct _KBDTABLES KBDTABLES
struct _VK_FUNCTION_PARAM VK_FPARAM
struct tagKBDTABLES_FE * PKBDTABLES_FE
struct tagKbdNlsLayer KBDNLSTABLES
struct _VK_TO_FUNCTION_TABLE * PVK_F
struct _MODIFIERS * PMODIFIERS
struct tagKBDTABLE_DESC KBDTABLE_DESC
#define KBD_PTR(T)
Definition: kbd.h:49
struct tagKbdNlsLayer * PKBDNLSTABLES
struct _VK_TO_BIT * PVK_TO_BIT
#define KBDTABLE_MULTI_MAX
Definition: kbd.h:199
struct _VK_FUNCTION_PARAM * PVK_FPARAM
struct _VSC_VK * PVSC_VK
struct _DEADKEY DEADKEY
struct _VK_TO_WCHAR_TABLE * PVK_TO_WCHAR_TABLE
struct _VSC_VK VSC_VK
struct tagKBDTABLE_MULTI KBDTABLE_MULTI
struct _VSC_LPWSTR VSC_LPWSTR
#define TYPEDEF_VK_TO_WCHARS(i)
Definition: kbd.h:87
struct _MODIFIERS MODIFIERS
#define TYPEDEF_LIGATURE(i)
Definition: kbd.h:132
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
Definition: kbd.h:111
WCHAR wchComposed
Definition: kbd.h:113
DWORD dwBoth
Definition: kbd.h:112
USHORT uFlags
Definition: kbd.h:114
KBD_PTR(VSC_LPWSTR *) pKeyNamesExt
KBD_PTR(PVK_TO_WCHAR_TABLE) pVkToWcharTable
KBD_PTR(DEADKEY_LPWSTR *) pKeyNamesDead
KBD_PTR(PVSC_VK) pVSCtoVK_E0
KBD_PTR(PVSC_VK) pVSCtoVK_E1
BYTE bMaxVSCtoVK
Definition: kbd.h:159
BYTE nLgMaxd
Definition: kbd.h:163
KBD_PTR(USHORT *) pusVSCtoVK
KBD_PTR(VSC_LPWSTR *) pKeyNames
KBD_PTR(PMODIFIERS) pCharModifiers
DWORD fLocaleFlags
Definition: kbd.h:162
KBD_PTR(PDEADKEY) pDeadKey
BYTE cbLgEntry
Definition: kbd.h:164
KBD_PTR(PLIGATURE1) pLigature
Definition: kbd.h:81
WORD wMaxModBits
Definition: kbd.h:83
KBD_PTR(PVK_TO_BIT) pVkToBit
BYTE ModNumber[]
Definition: kbd.h:84
BYTE NLSFEProcIndex
Definition: kbd.h:237
ULONG NLSFEProcParam
Definition: kbd.h:238
Definition: kbd.h:76
BYTE ModBits
Definition: kbd.h:78
BYTE Vk
Definition: kbd.h:77
BYTE NLSFEProcType
Definition: kbd.h:244
VK_FPARAM NLSFEProcAlt[8]
Definition: kbd.h:248
BYTE NLSFEProcCurrent
Definition: kbd.h:245
VK_FPARAM NLSFEProc[8]
Definition: kbd.h:247
BYTE NLSFEProcSwitch
Definition: kbd.h:246
BYTE nModifications
Definition: kbd.h:107
KBD_PTR(PVK_TO_WCHARS1) pVkToWchars
BYTE vsc
Definition: kbd.h:123
KBD_PTR(LPWSTR) pwsz
Definition: kbd.h:127
USHORT Vk
Definition: kbd.h:129
BYTE Vsc
Definition: kbd.h:128
DWORD dwType
Definition: kbd.h:265
DWORD dwSubType
Definition: kbd.h:266
KBDTABLES Base
Definition: kbd.h:264
WCHAR wszDllName[32]
Definition: kbd.h:194
DWORD dwType
Definition: kbd.h:195
DWORD dwSubType
Definition: kbd.h:196
KBDTABLE_DESC aKbdTables[KBDTABLE_MULTI_MAX]
Definition: kbd.h:204
UINT nTables
Definition: kbd.h:203
ULONG NumOfVkToF
Definition: kbd.h:255
KBD_PTR(PVK_F) pVkToF
INT NumOfMouseVKey
Definition: kbd.h:257
USHORT OEMIdentifier
Definition: kbd.h:253
USHORT LayoutInformation
Definition: kbd.h:254
KBD_PTR(PUSHORT) pusMouseVKey
uint16_t * LPWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
uint16_t * PUSHORT
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
unsigned char BYTE
Definition: xxhash.c:193