Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
keymap.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_KEYMAP_H
27#define _ULTIBO_KEYMAP_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/globaltypes.h"
34#include "ultibo/globalconst.h"
35
37#define KEYMAP_KEY_COUNT 256
38#define KEYMAP_ROW_COUNT 4
39#define KEYMAP_ROW_SIZE sizeof(uint16_t)
40
41#define KEYMAP_MAX_CAPSKEYS 50
42#define KEYMAP_MAX_DEADKEYS 5
43#define KEYMAP_MAX_RESOLVES 20
44
46#define KEYMAP_SIGNATURE 0x863FDBA1
47
49#define KEYMAP_NAME_LENGTH SIZE_64
50#define KEYMAP_DESC_LENGTH SIZE_128
51
53#define KEYMAP_MODE_NONE 0
54
56#define KEYMAP_FLAG_NONE 0x00000000
57#define KEYMAP_FLAG_ALTGR 0x00000001
58#define KEYMAP_FLAG_CAPS_ALL 0x00000002
59#define KEYMAP_FLAG_CAPS_ASCII 0x00000004
60
62#define KEYMAP_INDEX_NORMAL 0
63#define KEYMAP_INDEX_SHIFT 1
64#define KEYMAP_INDEX_ALTGR 2
65#define KEYMAP_INDEX_SHIFT_ALTGR 3
66
67#define KEYMAP_INDEX_COUNT 4
68
70
72typedef struct _KEYMAP_HEADER
73{
74 uint32_t mode;
75 uint32_t flags;
76 uint32_t keycount;
77 uint32_t rowcount;
78 char name[256];
79 char description[256];
81
83typedef struct _KEYMAP_DATA
84{
85 uint16_t data[256][KEYMAP_INDEX_COUNT];
87
89typedef uint16_t KEYMAP_CHARS[];
90
92typedef struct _KEYMAP_CAPSKEY
93{
94 uint16_t first;
95 uint16_t last;
97
104
106typedef struct _KEYMAP_RESOLVE
107{
108 uint16_t key;
109 uint8_t index;
110 uint16_t code;
112
120
127
139
141
143typedef uint32_t STDCALL (*keymap_enumerate_cb)(KEYMAP_HANDLE handle, void *data);
144
147{
148 // Keymap Properties
149 uint32_t signature;
150 uint32_t keymapmode;
151 uint32_t keymapflags;
154 // Driver Properties
155 void *keydata;
156 uint32_t keycount;
157 uint32_t rowcount;
160 // Internal Properties
163};
164
166
175
186KEYMAP_HANDLE STDCALL keymap_load_ex(KEYMAP_HEADER *header, KEYMAP_DATA *data, KEYMAP_CAPSKEYS *capskeys, KEYMAP_DEADKEYS *deadkeys, uint32_t size, KEYMAP_PROPERTIES *properties);
187
194
200uint32_t STDCALL keymap_get_name(KEYMAP_HANDLE handle, char *name, uint32_t len);
201
207uint32_t STDCALL keymap_get_description(KEYMAP_HANDLE handle, char *description, uint32_t len);
208
216
224uint16_t STDCALL keymap_get_key_code(KEYMAP_HANDLE handle, uint16_t scancode, uint8_t index);
225
232char STDCALL keymap_get_char_code(KEYMAP_HANDLE handle, uint16_t keycode);
233
241
249
257BOOL STDCALL keymap_check_deadkey(KEYMAP_HANDLE handle, uint16_t scancode, uint8_t index);
258
269BOOL STDCALL keymap_resolve_deadkey(KEYMAP_HANDLE handle, uint16_t deadcode, uint16_t scancode, uint8_t deadindex, uint8_t scanindex, uint16_t *keycode);
270
278
285
292
298uint32_t STDCALL keymap_enumerate(keymap_enumerate_cb callback, void *data);
299
301
306
311
316
321
322#ifdef __cplusplus
323}
324#endif
325
326#endif // _ULTIBO_KEYMAP_H
#define STDCALL
Definition globaltypes.h:45
HANDLE KEYMAP_HANDLE
Definition globaltypes.h:123
_Bool BOOL
Built in Boolean type (1 byte) (Redeclared here for flexibility).
Definition globaltypes.h:55
wchar_t WCHAR
Standard WideChar type (2 bytes) (Redeclared here for flexibility).
Definition globaltypes.h:58
uint16_t KEYMAP_CHARS[]
Definition keymap.h:89
KEYMAP_HANDLE STDCALL keymap_load(KEYMAP_HEADER *header, KEYMAP_DATA *data, uint32_t size)
Load a Keymap from a keymap data block and add to the Keymap table.
BOOL STDCALL keymap_check_capskey(KEYMAP_HANDLE handle, uint16_t scancode)
Check if a scan code is affected by the Caps Lock key in the specified keymap.
struct _KEYMAP_HEADER KEYMAP_HEADER
uint32_t STDCALL keymap_get_description(KEYMAP_HANDLE handle, char *description, uint32_t len)
Get the description of the specified keymap.
KEYMAP_ENTRY *STDCALL keymap_check(KEYMAP_ENTRY *keymap)
Check if the supplied Keymap is in the Keymap table.
KEYMAP_HANDLE STDCALL keymap_get_default(void)
Get the current default keymap.
#define KEYMAP_DESC_LENGTH
Length of keymap description.
Definition keymap.h:50
KEYMAP_HANDLE STDCALL keymap_find_by_description(const char *description)
Find a keymap by description.
uint32_t STDCALL keymap_get_properties(KEYMAP_HANDLE handle, KEYMAP_PROPERTIES *properties)
Get the properties of the specified keymap.
struct _KEYMAP_DEADKEYS KEYMAP_DEADKEYS
struct _KEYMAP_DATA KEYMAP_DATA
BOOL STDCALL keymap_resolve_deadkey(KEYMAP_HANDLE handle, uint16_t deadcode, uint16_t scancode, uint8_t deadindex, uint8_t scanindex, uint16_t *keycode)
Resolve a Dead Key and the next scan code to a key code value.
#define KEYMAP_MAX_DEADKEYS
Maximum number of keys that can be listed in the TKeymapDeadkeys structure.
Definition keymap.h:42
uint16_t STDCALL keymap_get_key_code(KEYMAP_HANDLE handle, uint16_t scancode, uint8_t index)
Resolve a scan code and index value to a key code using the specified keymap.
struct _KEYMAP_ENTRY KEYMAP_ENTRY
Definition keymap.h:140
uint32_t STDCALL keymap_get_name(KEYMAP_HANDLE handle, char *name, uint32_t len)
Get the name of the specified keymap.
uint32_t STDCALL keymap_get_count(void)
Get the current keymap count.
uint32_t STDCALL(* keymap_enumerate_cb)(KEYMAP_HANDLE handle, void *data)
Definition keymap.h:143
BOOL STDCALL keymap_check_flag(KEYMAP_HANDLE handle, uint32_t flag)
Check if a specified keymap has a particular flag set or not.
uint32_t STDCALL keymap_enumerate(keymap_enumerate_cb callback, void *data)
Enumerate all loaded keymaps.
struct _KEYMAP_DEADKEY KEYMAP_DEADKEY
struct _KEYMAP_CAPSKEY KEYMAP_CAPSKEY
KEYMAP_HANDLE STDCALL keymap_load_ex(KEYMAP_HEADER *header, KEYMAP_DATA *data, KEYMAP_CAPSKEYS *capskeys, KEYMAP_DEADKEYS *deadkeys, uint32_t size, KEYMAP_PROPERTIES *properties)
Load a Keymap from a keymap data block and add to the Keymap table.
#define KEYMAP_MAX_RESOLVES
Maximum number of resolves that can be listed in the TKeymapDeadkey structure.
Definition keymap.h:43
WCHAR STDCALL keymap_get_char_unicode(KEYMAP_HANDLE handle, uint16_t keycode)
Resolve a key code value to a Unicode character code using the specified keymap.
#define KEYMAP_NAME_LENGTH
Length of keymap name.
Definition keymap.h:49
char STDCALL keymap_get_char_code(KEYMAP_HANDLE handle, uint16_t keycode)
Resolve a key code value to an ANSI character code using the specified keymap.
struct _KEYMAP_CAPSKEYS KEYMAP_CAPSKEYS
BOOL STDCALL keymap_check_deadkey(KEYMAP_HANDLE handle, uint16_t scancode, uint8_t index)
Check if a scan code represents a Dead Key in the specified keymap.
uint32_t STDCALL keymap_set_default(KEYMAP_HANDLE handle)
Set the current default keymap.
uint32_t STDCALL keymap_unload(KEYMAP_HANDLE handle)
Unload an existing keymap and remove from the Keymap table.
#define KEYMAP_INDEX_COUNT
Definition keymap.h:67
struct _KEYMAP_PROPERTIES KEYMAP_PROPERTIES
Definition keymap.h:129
#define KEYMAP_MAX_CAPSKEYS
Maximum number of keys that can be listed in the TKeymapCapskeys structure.
Definition keymap.h:41
KEYMAP_HANDLE STDCALL keymap_find_by_name(const char *name)
Find a keymap by name.
struct _KEYMAP_RESOLVE KEYMAP_RESOLVE
Definition keymap.h:100
KEYMAP_CAPSKEY keys[KEYMAP_MAX_CAPSKEYS]
Definition keymap.h:102
uint32_t count
Definition keymap.h:101
Definition keymap.h:93
uint16_t last
Last key in caps key range (SCAN_CODE_* value)(Make first and last the same for a single key).
Definition keymap.h:95
uint16_t first
First key in caps key range (SCAN_CODE_* value).
Definition keymap.h:94
Definition keymap.h:84
uint16_t data[256][KEYMAP_INDEX_COUNT]
Key mapping data, 4 words for Normal, Shift, AltGr, Shift+AltGr for each of the 256 keys (See KEY_COD...
Definition keymap.h:85
Definition keymap.h:123
KEYMAP_DEADKEY keys[KEYMAP_MAX_DEADKEYS]
Definition keymap.h:125
uint32_t count
Definition keymap.h:124
Definition keymap.h:115
KEYMAP_RESOLVE resolves[KEYMAP_MAX_RESOLVES]
Definition keymap.h:118
uint8_t index
The index state in which the key behaves as a deadkey (eg KEYMAP_INDEX_NORMAL).
Definition keymap.h:117
uint16_t key
The scan code of the key which behaves as a deadkey (SCAN_CODE_* value).
Definition keymap.h:116
Definition keymap.h:147
KEYMAP_ENTRY * prev
Previous entry in Keymap table.
Definition keymap.h:161
KEYMAP_DEADKEYS * deadkeysdata
Keymap Deadkeys data (Keys which behave as Dead keys).
Definition keymap.h:159
KEYMAP_ENTRY * next
Next entry in Keymap table.
Definition keymap.h:162
char keymapname[KEYMAP_NAME_LENGTH]
Keymap name.
Definition keymap.h:152
KEYMAP_CAPSKEYS * capskeysdata
Keymap Capskeys data (Keys affected by Caps Lock).
Definition keymap.h:158
uint32_t keymapflags
Keymap flags (eg KEYMAP_FLAG_ALTGR).
Definition keymap.h:151
uint32_t rowcount
Number of index rows in key data (Default: KEYMAP_ROW_COUNT).
Definition keymap.h:157
uint32_t signature
Signature for entry validation.
Definition keymap.h:149
char keymapdescription[KEYMAP_DESC_LENGTH]
Keymap description.
Definition keymap.h:153
uint32_t keymapmode
Keymap mode (eg KEYMAP_MODE_NONE).
Definition keymap.h:150
void * keydata
Keymap key data.
Definition keymap.h:155
uint32_t keycount
Number of keys in key data (Default: KEYMAP_KEY_COUNT).
Definition keymap.h:156
Definition keymap.h:73
char description[256]
Keymap description //NOT null terminated, index 0 is the length.
Definition keymap.h:79
uint32_t mode
Keymap mode (eg KEYMAP_MODE_NONE).
Definition keymap.h:74
uint32_t flags
Keymap flags (eg KEYMAP_FLAG_ALTGR).
Definition keymap.h:75
char name[256]
Keymap name //NOT null terminated, index 0 is the length.
Definition keymap.h:78
uint32_t rowcount
Number of index rows in keymap (Default: KEYMAP_ROW_COUNT).
Definition keymap.h:77
uint32_t keycount
Number of keys in keymap (Default: KEYMAP_KEY_COUNT).
Definition keymap.h:76
Definition keymap.h:131
char keymapname[KEYMAP_NAME_LENGTH]
Keymap name.
Definition keymap.h:136
uint32_t keymapflags
Keymap flags (eg KEYMAP_FLAG_ALTGR).
Definition keymap.h:133
uint32_t rowcount
Number of index rows in keymap (Default: KEYMAP_ROW_COUNT).
Definition keymap.h:135
char keymapdescription[KEYMAP_DESC_LENGTH]
Keymap description.
Definition keymap.h:137
uint32_t keymapmode
Keymap mode (eg KEYMAP_MODE_NONE).
Definition keymap.h:132
uint32_t keycount
Number of keys in keymap (Default: KEYMAP_KEY_COUNT).
Definition keymap.h:134
Definition keymap.h:107
uint16_t code
The key code of the resulting character (KEY_CODE_* value).
Definition keymap.h:110
uint8_t index
The index state of the key pressed after the deadkey (eg KEYMAP_INDEX_NORMAL).
Definition keymap.h:109
uint16_t key
The scan code of the key pressed after the deadkey (SCAN_CODE_* value).
Definition keymap.h:108