KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
keyboard.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/maple/keyboard.h
4 Copyright (C) 2000-2002 Jordan DeLong and Megan Potter
5 Copyright (C) 2012 Lawrence Sebald
6 Copyright (C) 2025 Falco Girgis
7
8*/
9
10/** \file dc/maple/keyboard.h
11 \brief Definitions for using the keyboard device.
12 \ingroup kbd
13
14 This file contains the definitions needed to access the Maple keyboard
15 device. Obviously, this corresponds to the MAPLE_FUNC_KEYBOARD function
16 code.
17
18 \author Jordan DeLong
19 \author Megan Potter
20 \author Lawrence Sebald
21 \author Falco Girgis
22*/
23
24#ifndef __DC_MAPLE_KEYBOARD_H
25#define __DC_MAPLE_KEYBOARD_H
26
27#include <sys/cdefs.h>
28__BEGIN_DECLS
29
30#include <arch/types.h>
31#include <dc/maple.h>
32#include <kos/regfield.h>
33
34#include <stdbool.h>
35#include <stdint.h>
36
37/** \defgroup kbd Keyboard
38 \brief Driver for the Dreamcast's Keyboard Input Device
39 \ingroup peripherals
40*/
41
42/** \defgroup kbd_status_grp Device Status
43 \brief Types relating to overall keyboard state
44 \ingroup kbd
45
46 Types and API functions revolving around individual constituents of
47 the overall keyboard state. These values can either be retrieved manually
48 with \ref kbd_polling.
49
50 @{
51*/
52
53/** \defgroup kbd_mods_grp Modifier Keys
54 \brief Types associated with keyboard modifier keys
55 \ingroup kbd_status_grp
56
57 Modifier keys are represented by the kbd_mods_t union type. Each key state
58 can be accessed by:
59 1. Directly using a convenience bit field.
60 2. Bitwise `AND` of kbd_mods_t::raw with one of the \ref kbd_mods_flags.
61
62 @{
63*/
64
65/** \defgroup kbd_mods_flags Flags
66 \brief Keyboard modifier key flags
67
68 These are the various modifiers that can be pressed on the keyboard. Their
69 current state is stored within kbd_cond_t::modifiers.
70
71 \sa kbd_mods_t::raw
72
73 @{
74*/
75/* Single-Key Modifiers */
76#define KBD_MOD_LCTRL BIT(0) /**< \brief Left Control key */
77#define KBD_MOD_LSHIFT BIT(1) /**< \brief Left Shift key */
78#define KBD_MOD_LALT BIT(2) /**< \brief Left alternate key */
79#define KBD_MOD_S1 BIT(3) /**< \brief S1 key */
80#define KBD_MOD_RCTRL BIT(4) /**< \brief Right Control key */
81#define KBD_MOD_RSHIFT BIT(5) /**< \brief Right Shift key */
82#define KBD_MOD_RALT BIT(6) /**< \brief Right Alternate key */
83#define KBD_MOD_S2 BIT(7) /**< \brief S2 key */
84
85/* Multi-Key Modifiers */
86/** \brief Either Control key */
87#define KBD_MOD_CTRL (KBD_MOD_LCTRL | KBD_MOD_RCTRL)
88/** \brief Either Shift key */
89#define KBD_MOD_SHIFT (KBD_MOD_LSHIFT | KBD_MOD_RSHIFT)
90/** \brief Either Alternate key */
91#define KBD_MOD_ALT (KBD_MOD_LALT | KBD_MOD_RALT)
92/** @} */
93
94/** \brief Modifier Keys
95
96 Convenience union containing the state of all keyboard modifier keys.
97
98 \sa kbd_mods_flags, kbd_state_t::modifiers
99*/
100typedef union kbd_mods {
101 /** \brief Convenience Bitfields */
102 struct {
103 uint8_t lctrl : 1; /**< \brief Left Control key */
104 uint8_t lshift : 1; /**< \brief Left Shift key */
105 uint8_t lalt : 1; /**< \brief Left Alternate key */
106 uint8_t s1 : 1; /**< \brief S1 key */
107 uint8_t rctrl : 1; /**< \brief Right Control key */
108 uint8_t rshift : 1; /**< \brief Right Shift key */
109 uint8_t ralt : 1; /**< \brief Right Alternate key */
110 uint8_t s2 : 1; /**< \brief S2 key */
111 };
112 uint8_t raw; /**< \brief Packed 8-bit unsigned integer of bitflags */
113} kbd_mods_t;
114
115/** @} */
116
117/** \defgroup kbd_leds_grp LEDs
118 \brief Types associated with keyboard LEDs
119 \ingroup kbd
120
121 LEDs are represented by the kbd_leds_t union type. Each individual LED
122 can be accessed by:
123 1. Directly using a convenience bit field.
124 2. Bitwise `AND` of kbd_leds_t::raw with one of the \ref kbd_led_flags.
125
126 @{
127*/
128
129/** \defgroup kbd_led_flags Flags
130 \brief Keyboard LED flags
131
132 These are the LEDs that can be turned on and off on the keyboard. This list
133 may not be exhaustive. Think of these sort of like an extension of the
134 modifiers list.
135
136 \sa kbd_leds_t::raw
137
138 @{
139*/
140#define KBD_LED_NUMLOCK BIT(0) /**< \brief Num Lock LED */
141#define KBD_LED_CAPSLOCK BIT(1) /**< \brief Caps Lock LED */
142#define KBD_LED_SCRLOCK BIT(2) /**< \brief Scroll Lock LED */
143#define KBD_LED_UNKNOWN1 BIT(3) /**< \brief Unknown LED 1 */
144#define KBD_LED_UNKNOWN2 BIT(4) /**< \brief Unknown LED 2 */
145#define KBD_LED_KANA BIT(5) /**< \brief Kana LED */
146#define KBD_LED_POWER BIT(6) /**< \brief Power LED */
147#define KBD_LED_SHIFT BIT(7) /**< \brief Shift LED */
148/** @} */
149
150/** \brief Keyboard LEDs
151
152 Union containing the state of all keyboard LEDs.
153
154 \sa kbd_led_flags, kbd_cond_t::leds
155*/
156typedef union kbd_leds {
157 /** \brief Convenience Bitfields */
158 struct {
159 uint8_t num_lock : 1; /**< \brief Num Lock LED */
160 uint8_t caps_lock : 1; /**< \brief Caps Lock LED */
161 uint8_t scroll_lock : 1; /**< \brief Scroll Lock LED */
162 uint8_t unknown1 : 1; /**< \brief Unknown LED 1 */
163 uint8_t unknown2 : 1; /**< \brief Unknown LED 2 */
164 uint8_t kana : 1; /**< \brief Kana LED */
165 uint8_t power : 1; /**< \brief Power LED */
166 uint8_t shift : 1; /**< \brief Shift LED */
167 };
168 uint8_t raw; /**< \brief Packed 8-bit unsigned integer of bitflags */
169} kbd_leds_t;
170
171/** @} */
172
173/** \brief Region Codes for the Dreamcast keyboard
174
175 This is the list of possible values for kbd_state_t::region.
176*/
177typedef enum kbd_region {
178 KBD_REGION_JP = 1, /**< \brief Japanese keyboard */
179 KBD_REGION_US = 2, /**< \brief US keyboard */
180 KBD_REGION_UK = 3, /**< \brief UK keyboard */
181 KBD_REGION_DE = 4, /**< \brief German keyboard */
182 KBD_REGION_FR = 5, /**< \brief French keyboard */
183 KBD_REGION_IT = 6, /**< \brief Italian keyboard (not supported yet) */
184 KBD_REGION_ES = 7 /**< \brief Spanish keyboard */
186
187/** \brief Raw Keyboard Key Identifiers
188
189 This is the list of keys that are on the keyboard that may be pressed. The
190 keyboard returns keys in this format.
191
192 \note
193 These are the raw keycodes returned by the US keyboard, and thus only cover
194 the keys on US keyboards (even though they can be used with other keyboards).
195*/
196typedef enum __packed kbd_key {
197 KBD_KEY_NONE = 0x00, /**< \brief No key */
198 KBD_KEY_ERROR = 0x01, /**< \brief ERROR_ROLLOVER */
199 KBD_KEY_ERR2 = 0x02, /**< \brief Unknown error */
200 KBD_KEY_ERR3 = 0x03, /**< \brief Unknown error */
201 KBD_KEY_A = 0x04, /**< \brief A key */
202 KBD_KEY_B = 0x05, /**< \brief B key */
203 KBD_KEY_C = 0x06, /**< \brief C key */
204 KBD_KEY_D = 0x07, /**< \brief D key */
205 KBD_KEY_E = 0x08, /**< \brief E key */
206 KBD_KEY_F = 0x09, /**< \brief F key */
207 KBD_KEY_G = 0x0a, /**< \brief G key */
208 KBD_KEY_H = 0x0b, /**< \brief H key */
209 KBD_KEY_I = 0x0c, /**< \brief I key */
210 KBD_KEY_J = 0x0d, /**< \brief J key */
211 KBD_KEY_K = 0x0e, /**< \brief K key */
212 KBD_KEY_L = 0x0f, /**< \brief L key */
213 KBD_KEY_M = 0x10, /**< \brief M key */
214 KBD_KEY_N = 0x11, /**< \brief N key */
215 KBD_KEY_O = 0x12, /**< \brief O key */
216 KBD_KEY_P = 0x13, /**< \brief P key */
217 KBD_KEY_Q = 0x14, /**< \brief Q key */
218 KBD_KEY_R = 0x15, /**< \brief R key */
219 KBD_KEY_S = 0x16, /**< \brief S key */
220 KBD_KEY_T = 0x17, /**< \brief T key */
221 KBD_KEY_U = 0x18, /**< \brief U key */
222 KBD_KEY_V = 0x19, /**< \brief V key */
223 KBD_KEY_W = 0x1a, /**< \brief W key */
224 KBD_KEY_X = 0x1b, /**< \brief X key */
225 KBD_KEY_Y = 0x1c, /**< \brief Y key */
226 KBD_KEY_Z = 0x1d, /**< \brief Z key */
227 KBD_KEY_1 = 0x1e, /**< \brief 1 key */
228 KBD_KEY_2 = 0x1f, /**< \brief 2 key */
229 KBD_KEY_3 = 0x20, /**< \brief 3 key */
230 KBD_KEY_4 = 0x21, /**< \brief 4 key */
231 KBD_KEY_5 = 0x22, /**< \brief 5 key */
232 KBD_KEY_6 = 0x23, /**< \brief 6 key */
233 KBD_KEY_7 = 0x24, /**< \brief 7 key */
234 KBD_KEY_8 = 0x25, /**< \brief 8 key */
235 KBD_KEY_9 = 0x26, /**< \brief 9 key */
236 KBD_KEY_0 = 0x27, /**< \brief 0 key */
237 KBD_KEY_ENTER = 0x28, /**< \brief Enter key */
238 KBD_KEY_ESCAPE = 0x29, /**< \brief Escape key */
239 KBD_KEY_BACKSPACE = 0x2a, /**< \brief Backspace key */
240 KBD_KEY_TAB = 0x2b, /**< \brief Tab key */
241 KBD_KEY_SPACE = 0x2c, /**< \brief Space key */
242 KBD_KEY_MINUS = 0x2d, /**< \brief Minus key */
243 KBD_KEY_PLUS = 0x2e, /**< \brief Plus key */
244 KBD_KEY_LBRACKET = 0x2f, /**< \brief Left Bracket key */
245 KBD_KEY_RBRACKET = 0x30, /**< \brief Right Bracket key */
246 KBD_KEY_BACKSLASH = 0x31, /**< \brief Backslash key */
247 KBD_KEY_SEMICOLON = 0x33, /**< \brief Semicolon key */
248 KBD_KEY_QUOTE = 0x34, /**< \brief Double Quote key */
249 KBD_KEY_TILDE = 0x35, /**< \brief Tilde key */
250 KBD_KEY_COMMA = 0x36, /**< \brief Comma key */
251 KBD_KEY_PERIOD = 0x37, /**< \brief Period key */
252 KBD_KEY_SLASH = 0x38, /**< \brief Slash key */
253 KBD_KEY_CAPSLOCK = 0x39, /**< \brief Caps Lock key */
254 KBD_KEY_F1 = 0x3a, /**< \brief F1 key */
255 KBD_KEY_F2 = 0x3b, /**< \brief F2 key */
256 KBD_KEY_F3 = 0x3c, /**< \brief F3 key */
257 KBD_KEY_F4 = 0x3d, /**< \brief F4 key */
258 KBD_KEY_F5 = 0x3e, /**< \brief F5 key */
259 KBD_KEY_F6 = 0x3f, /**< \brief F6 key */
260 KBD_KEY_F7 = 0x40, /**< \brief F7 key */
261 KBD_KEY_F8 = 0x41, /**< \brief F8 key */
262 KBD_KEY_F9 = 0x42, /**< \brief F9 key */
263 KBD_KEY_F10 = 0x43, /**< \brief F10 key */
264 KBD_KEY_F11 = 0x44, /**< \brief F11 key */
265 KBD_KEY_F12 = 0x45, /**< \brief F12 key */
266 KBD_KEY_PRINT = 0x46, /**< \brief Print Screen key */
267 KBD_KEY_SCRLOCK = 0x47, /**< \brief Scroll Lock key */
268 KBD_KEY_PAUSE = 0x48, /**< \brief Pause key */
269 KBD_KEY_INSERT = 0x49, /**< \brief Insert key */
270 KBD_KEY_HOME = 0x4a, /**< \brief Home key */
271 KBD_KEY_PGUP = 0x4b, /**< \brief Page Up key */
272 KBD_KEY_DEL = 0x4c, /**< \brief Delete key */
273 KBD_KEY_END = 0x4d, /**< \brief End key */
274 KBD_KEY_PGDOWN = 0x4e, /**< \brief Page Down key */
275 KBD_KEY_RIGHT = 0x4f, /**< \brief Right Arrow key */
276 KBD_KEY_LEFT = 0x50, /**< \brief Left Arrow key */
277 KBD_KEY_DOWN = 0x51, /**< \brief Down Arrow key */
278 KBD_KEY_UP = 0x52, /**< \brief Up Arrow key */
279 KBD_KEY_PAD_NUMLOCK = 0x53, /**< \brief Keypad Numlock key */
280 KBD_KEY_PAD_DIVIDE = 0x54, /**< \brief Keypad Divide key */
281 KBD_KEY_PAD_MULTIPLY = 0x55, /**< \brief Keypad Multiply key */
282 KBD_KEY_PAD_MINUS = 0x56, /**< \brief Keypad Minus key */
283 KBD_KEY_PAD_PLUS = 0x57, /**< \brief Keypad Plus key */
284 KBD_KEY_PAD_ENTER = 0x58, /**< \brief Keypad Enter key */
285 KBD_KEY_PAD_1 = 0x59, /**< \brief Keypad 1 key */
286 KBD_KEY_PAD_2 = 0x5a, /**< \brief Keypad 2 key */
287 KBD_KEY_PAD_3 = 0x5b, /**< \brief Keypad 3 key */
288 KBD_KEY_PAD_4 = 0x5c, /**< \brief Keypad 4 key */
289 KBD_KEY_PAD_5 = 0x5d, /**< \brief Keypad 5 key */
290 KBD_KEY_PAD_6 = 0x5e, /**< \brief Keypad 6 key */
291 KBD_KEY_PAD_7 = 0x5f, /**< \brief Keypad 7 key */
292 KBD_KEY_PAD_8 = 0x60, /**< \brief Keypad 8 key */
293 KBD_KEY_PAD_9 = 0x61, /**< \brief Keypad 9 key */
294 KBD_KEY_PAD_0 = 0x62, /**< \brief Keypad 0 key */
295 KBD_KEY_PAD_PERIOD = 0x63, /**< \brief Keypad Period key */
296 KBD_KEY_S3 = 0x65 /**< \brief S3 key */
298
299/** \brief Converts a kbd_key_t value into its corresponding ASCII value
300
301 This function attempts to convert \p key to its ASCII representation
302 using an internal translation table and additional keyboard state context.
303 To note, this is actually ISO-8859-15 where applicable for non-English
304 regions.
305
306 \param key The raw key type to convert to ASCII.
307 \param region The region type of the keyboard containing the key.
308 \param mods The modifier flags impacting the key.
309 \param leds The LED state flags impacting the key.
310
311 \returns The ASCII value corresponding to \p key or NULL if
312 the translation was unsuccessful.
313*/
315 kbd_mods_t mods, kbd_leds_t leds);
316
317/** \defgroup key_states Key States
318 \brief States each key can be in.
319
320 These are the different 'states' each key can be in. They are stored in
321 kbd_state_t->matrix, and manipulated/checked by kbd_check_poll.
322
323 none-> pressed or none
324 was pressed-> pressed or none
325 pressed-> was_pressed
326 @{
327*/
328#define KEY_STATE_NONE 0
329#define KEY_STATE_WAS_PRESSED 1
330#define KEY_STATE_PRESSED 2
331/** @} */
332
333/** \brief Maximum number of keys the DC can read simultaneously.
334
335 This is a hardware constant. The define prevents the magic number '6' from appearing.
336**/
337#define MAX_PRESSED_KEYS 6
338
339/** \brief Maximum number of keys a DC keyboard can have.
340
341 This is a hardware constant. The define prevents the magic number '256' from appearing.
342**/
343#define KBD_MAX_KEYS 256
344
345/* Short-term compatibility helper. */
346static const int MAX_KBD_KEYS __depr("Please use KBD_MAX_KEYS.") = KBD_MAX_KEYS;
347
348typedef void kbd_keymap_t __depr("Please open an issue, there should be no reason for external code to have used this.");
349
350/** \brief Keyboard raw condition structure.
351
352 This structure is what the keyboard responds with as its current status.
353
354 \headerfile dc/maple/keyboard.h
355*/
356typedef struct {
357 kbd_mods_t modifiers; /**< \brief Bitmask of set modifiers. */
358 kbd_leds_t leds; /**< \brief Bitmask of set LEDs */
359 kbd_key_t keys[MAX_PRESSED_KEYS]; /**< \brief Key codes for currently pressed keys. */
360} kbd_cond_t;
361
362/** \brief Keyboard status structure.
363
364 This structure holds information about the current status of the keyboard
365 device. This is what maple_dev_status() will return.
366
367 \headerfile dc/maple/keyboard.h
368*/
369typedef struct kbd_state {
370 /** \brief The latest raw condition of the keyboard. */
372
373 /** \brief Key array.
374
375 This array lists the state of all possible keys on the keyboard. It can
376 be used for key repeat and debouncing. This will be non-zero if the key
377 is currently being pressed.
378
379 \see kbd_keys
380 */
381 uint8_t matrix[KBD_MAX_KEYS];
382
383 /** \brief Modifier key status. Stored to track changes. */
384 union {
385 int shift_keys __depr("Please see kbd_mods_t and use last_modifiers.raw to access this.");
387 };
388
389 /** \brief Keyboard type/region. */
392
393/** @} */
394
395/** \defgroup kbd_input Querying for Input
396 \brief Various methods for checking keyboard input
397 \ingroup kbd
398
399 There are 2 different ways to check for input with the keyboard API:
400
401 Mechanism | Description
402 ----------------------|--------------------------------------------
403 \ref kbd_polling | Manual checks each key state every frame
404 \ref kbd_queue | Monitor for new key press events every frame
405
406 @{
407*/
408
409/** \defgroup kbd_polling State Polling
410 \brief Frame-based polling for keyboard input
411
412 One method of checking for key input is to simply poll
413 kbd_state_t::matrix for the desired key states each frame.
414
415 First, lets grab a pointer to the kbd_state_t:
416 \code{.c}
417 kbd_state_t *kbd = kbd_get_state(device);
418 \endcode
419 Then let's "move" every frame an arrow key is held down:
420 \code{.c}
421 if(kbd->matrix[KBD_KEY_LEFT] == KEY_STATE_PRESSED)
422 printf("Moving left!\n");
423 if(kbd->matrix[KBD_KEY_RIGHT] == KEY_STATE_PRESSED)
424 printf("Moving right!\n");
425 if(kbd->matrix[KBD_KEY_UP] == KEY_STATE_PRESSED)
426 printf("Moving up!\n");
427 if(kbd->matrix[KBD_KEY_DOWN] == KEY_STATE_PRESSED)
428 printf("Moving down!\n");
429 \endcode
430 Finally, let's charge an "attack" incrementing the charge for each
431 frame that the key is held and resetting when the key is released:
432 \code{.c}
433 if(kbd->matrix[KBD_KEY_SPACE] == KEY_STATE_PRESSED)
434 charge++;
435 if(kbd->matrix[KBD_KEY_SPACE] == KEY_STATE_WAS_PRESSED) {
436 printf("Releasing a charged attack of %i!\n", charge);
437 charge = 0;
438 }
439 \endcode
440 @{
441*/
442
443/** \brief Retrieves the keyboard state from a maple device
444
445 Accessor method for safely retrieving a kbd_state_t from a maple_device_t
446 of a `MAPLE_FUNC_KEYBOARD` type. This function also checks for whether
447 the given device is actually a keyboard and for whether it is currently
448 valid.
449
450 \param device Handle corresponding to a `MAPLE_FUNC_KEYBOARD`
451 device.
452
453 \retval kbd_state_t* A pointer to the internal keyboard state on success.
454 \retval NULL On failure.
455
456*/
458
459/** @} */
460
461/** \defgroup kbd_queue Queue Monitoring
462 \brief Monitor queue for key press events.
463
464 \par Popping from the Queue
465 One method of checking for key input is to use the internal key press
466 queue. This is most frequently used when keyboard input is used within
467 a text processing context, which is only concerned with individual key
468 press events, rather than the frame-by-frame state.
469
470 \par
471 We simply pop keys off of the queue in a loop, until the queue is empty:
472 \code{.c}
473 int k;
474
475 while((k = kbd_queue_pop(device, 1)) != KBD_QUEUE_END)
476 printf("Key pressed: %c!\n", (char)k);
477 \endcode
478 \par Repeated Presses
479 As with a text processor, a key which has been held down for a duration of
480 time will generate periodic key press events which will be pushed onto the
481 queue.
482
483 @{
484*/
485
486/** \brief Size of a keyboard queue.
487
488 Each keyboard queue will hold this many elements. Once the queue fills, no
489 new elements will be placed on the queue. As long as you check the queue
490 relatively frequently, the default of 16 should be plenty.
491
492 \note This <strong>MUST</strong> be a power of two.
493*/
494#define KBD_QUEUE_SIZE 16
495
496/** \brief Delimiter value for kbd_queue_pop()
497
498 Value returned from kbd_queue_pop() when there are no more keys in the
499 queue.
500
501 \sa kbd_queue_pop()
502*/
503#define KBD_QUEUE_END -1
504
505/** \brief Configures held key auto-repeat intervals
506
507 This function is used to configure the specific timing behavior for how the
508 internal queue treats a key which is being held down. Giving non-zero values
509 for both parameters will cause the held key to be re-enqueued every
510 \p interval milliseconds after it has been held for the initial \p start time
511 in milliseconds.
512
513 Specifying a value of zero for the two parameters disables this repeating key
514 behavior.
515
516 \note
517 By default, the \p start time is 600ms while the repeating \p interval is 20ms.
518
519 \param start The duration after which the held key starts to
520 register as repeated key presses (or zero to disable
521 this behavior).
522 \param interval The duration between subsequent key repeats after the
523 initial \p start time has elapsed.
524
525 \sa kbd_queue_pop()
526*/
527void kbd_set_repeat_timing(uint16_t start, uint16_t interval);
528
529/** \brief Pop a key off a specific keyboard's queue.
530
531 This function pops the front element off of the specified keyboard queue,
532 and returns the value of that key to the caller.
533
534 If the \p xlat parameter is true and the key represents an ISO-8859-1
535 character, that is the value that will be returned from this function.
536 If the key cannot be converted into a valid ISO-8859-1 character the
537 raw key code, shifted up by 8 bits, will be returned.
538
539 If the \p xlat parameter is false, the lower 8 bits of the returned
540 value will be the raw key code. The next 8 bits will be the modifier
541 keys that were down when the key was pressed (kbd_mods_t). The next
542 8 bits will be the lock key/LED statuses (kbd_leds_t).
543
544 \param dev The keyboard device to read from.
545 \param xlat Set to true to do key translation. Otherwise,
546 you'll simply get the raw key value. Raw key values
547 are not mapped at all, so you are responsible for
548 figuring out what it is by the region.
549
550 \return The value at the front of the queue, or KBD_QUEUE_END
551 if there are no keys in the queue.
552*/
553int kbd_queue_pop(maple_device_t *dev, bool xlat);
554
555/** \brief Activate or deactivate global key queueing.
556 \deprecated
557
558 This function will turn the internal keyboard queueing on or off. Note that
559 there is only one queue for the whole system, no matter how many keyboards
560 are attached, and the queue is of fairly limited length. Turning queueing
561 off is useful (for instance) in a game where individual keypresses don't
562 mean as much as having the keys up or down does.
563
564 You can clear the queue (without popping all the keys off) by setting the
565 active value to a different value than it was.
566
567 The queue is by default on, unless you turn it off.
568
569 \param active Set to non-zero to activate the queue.
570 \note The global queue does not account for non-US
571 keyboard layouts and is deprecated. Please use the
572 individual queues instead for future code.
573*/
575
576/** \brief Pop a key off the global keyboard queue.
577 \deprecated
578
579 This function pops the front off of the keyboard queue, and returns the
580 value to the caller. The value returned will be the ASCII value of the key
581 pressed (accounting for the shift keys being pressed).
582
583 If a key does not have an ASCII value associated with it, the raw key code
584 will be returned, shifted up by 8 bits.
585
586 \return The value at the front of the queue, or KBD_QUEUE_END
587 if there are no keys in the queue or queueing is off.
588 \note This function does not account for non-US keyboard
589 layouts properly (for compatibility with old code),
590 and is deprecated. Use the individual keyboard
591 queues instead to properly account for non-US
592 keyboards.
593 \see kbd_queue_pop()
594*/
596
597/** @} */
598
599/** @} */
600
601/* \cond */
602/* Init / Shutdown */
603void kbd_init(void);
604void kbd_shutdown(void);
605/* \endcond */
606
607__END_DECLS
608
609#endif /* __DC_MAPLE_KEYBOARD_H */
kbd_state_t * kbd_get_state(maple_device_t *device)
Retrieves the keyboard state from a maple device.
void kbd_set_repeat_timing(uint16_t start, uint16_t interval)
Configures held key auto-repeat intervals.
int kbd_queue_pop(maple_device_t *dev, bool xlat)
Pop a key off a specific keyboard's queue.
int kbd_get_key(void) __deprecated
Pop a key off the global keyboard queue.
void kbd_set_queue(int active) __deprecated
Activate or deactivate global key queueing.
kbd_region_t
Region Codes for the Dreamcast keyboard.
Definition keyboard.h:177
static const int MAX_KBD_KEYS("Please use KBD_MAX_KEYS.")
#define MAX_PRESSED_KEYS
Maximum number of keys the DC can read simultaneously.
Definition keyboard.h:337
char kbd_key_to_ascii(kbd_key_t key, kbd_region_t region, kbd_mods_t mods, kbd_leds_t leds)
Converts a kbd_key_t value into its corresponding ASCII value.
enum __packed kbd_key
Raw Keyboard Key Identifiers.
Definition keyboard.h:196
#define KBD_MAX_KEYS
Maximum number of keys a DC keyboard can have.
Definition keyboard.h:343
enum __packed kbd_key kbd_key_t
Raw Keyboard Key Identifiers.
void kbd_keymap_t("Please open an issue, there should be no reason for external code to have used this.")
Definition keyboard.h:348
@ KBD_REGION_FR
French keyboard.
Definition keyboard.h:182
@ KBD_REGION_US
US keyboard.
Definition keyboard.h:179
@ KBD_REGION_IT
Italian keyboard (not supported yet)
Definition keyboard.h:183
@ KBD_REGION_UK
UK keyboard.
Definition keyboard.h:180
@ KBD_REGION_ES
Spanish keyboard.
Definition keyboard.h:184
@ KBD_REGION_DE
German keyboard.
Definition keyboard.h:181
@ KBD_REGION_JP
Japanese keyboard.
Definition keyboard.h:178
#define __packed
Force a structure, enum, or other type to be packed as small as possible.
Definition cdefs.h:73
#define __deprecated
Mark something as deprecated.
Definition cdefs.h:116
KBD_KEY_R
R key.
Definition keyboard.h:218
KBD_KEY_C
C key.
Definition keyboard.h:203
KBD_KEY_LEFT
Left Arrow key.
Definition keyboard.h:276
KBD_KEY_F9
F9 key.
Definition keyboard.h:262
KBD_KEY_PAD_6
Keypad 6 key.
Definition keyboard.h:290
KBD_KEY_PERIOD
Period key.
Definition keyboard.h:251
KBD_KEY_PLUS
Plus key.
Definition keyboard.h:243
KBD_KEY_F4
F4 key.
Definition keyboard.h:257
KBD_KEY_ERR3
Unknown error.
Definition keyboard.h:200
KBD_KEY_G
G key.
Definition keyboard.h:207
KBD_KEY_2
2 key
Definition keyboard.h:228
KBD_KEY_O
O key.
Definition keyboard.h:215
KBD_KEY_N
N key.
Definition keyboard.h:214
KBD_KEY_QUOTE
Double Quote key.
Definition keyboard.h:248
KBD_KEY_TAB
Tab key.
Definition keyboard.h:240
KBD_KEY_COMMA
Comma key.
Definition keyboard.h:250
KBD_KEY_DEL
Delete key.
Definition keyboard.h:272
KBD_KEY_PAUSE
Pause key.
Definition keyboard.h:268
KBD_KEY_H
H key.
Definition keyboard.h:208
KBD_KEY_SEMICOLON
Semicolon key.
Definition keyboard.h:247
KBD_KEY_B
B key.
Definition keyboard.h:202
KBD_KEY_PAD_DIVIDE
Keypad Divide key.
Definition keyboard.h:280
KBD_KEY_8
8 key
Definition keyboard.h:234
KBD_KEY_END
End key.
Definition keyboard.h:273
KBD_KEY_3
3 key
Definition keyboard.h:229
KBD_KEY_0
0 key
Definition keyboard.h:236
KBD_KEY_K
K key.
Definition keyboard.h:211
KBD_KEY_TILDE
Tilde key.
Definition keyboard.h:249
KBD_KEY_F6
F6 key.
Definition keyboard.h:259
KBD_KEY_PAD_1
Keypad 1 key.
Definition keyboard.h:285
KBD_KEY_F10
F10 key.
Definition keyboard.h:263
KBD_KEY_L
L key.
Definition keyboard.h:212
KBD_KEY_ERROR
ERROR_ROLLOVER.
Definition keyboard.h:198
KBD_KEY_I
I key.
Definition keyboard.h:209
KBD_KEY_F12
F12 key.
Definition keyboard.h:265
KBD_KEY_Z
Z key.
Definition keyboard.h:226
KBD_KEY_PAD_9
Keypad 9 key.
Definition keyboard.h:293
KBD_KEY_T
T key.
Definition keyboard.h:220
KBD_KEY_D
D key.
Definition keyboard.h:204
KBD_KEY_PRINT
Print Screen key.
Definition keyboard.h:266
KBD_KEY_PAD_NUMLOCK
Keypad Numlock key.
Definition keyboard.h:279
KBD_KEY_F5
F5 key.
Definition keyboard.h:258
KBD_KEY_SCRLOCK
Scroll Lock key.
Definition keyboard.h:267
KBD_KEY_PAD_MINUS
Keypad Minus key.
Definition keyboard.h:282
KBD_KEY_MINUS
Minus key.
Definition keyboard.h:242
KBD_KEY_ESCAPE
Escape key.
Definition keyboard.h:238
KBD_KEY_PAD_3
Keypad 3 key.
Definition keyboard.h:287
KBD_KEY_BACKSLASH
Backslash key.
Definition keyboard.h:246
KBD_KEY_PGUP
Page Up key.
Definition keyboard.h:271
KBD_KEY_SPACE
Space key.
Definition keyboard.h:241
KBD_KEY_PAD_0
Keypad 0 key.
Definition keyboard.h:294
KBD_KEY_F11
F11 key.
Definition keyboard.h:264
KBD_KEY_PAD_5
Keypad 5 key.
Definition keyboard.h:289
KBD_KEY_E
E key.
Definition keyboard.h:205
KBD_KEY_S
S key.
Definition keyboard.h:219
KBD_KEY_PAD_2
Keypad 2 key.
Definition keyboard.h:286
KBD_KEY_6
6 key
Definition keyboard.h:232
KBD_KEY_9
9 key
Definition keyboard.h:235
KBD_KEY_M
M key.
Definition keyboard.h:213
KBD_KEY_RIGHT
Right Arrow key.
Definition keyboard.h:275
KBD_KEY_J
J key.
Definition keyboard.h:210
KBD_KEY_W
W key.
Definition keyboard.h:223
KBD_KEY_PAD_PLUS
Keypad Plus key.
Definition keyboard.h:283
KBD_KEY_PGDOWN
Page Down key.
Definition keyboard.h:274
KBD_KEY_5
5 key
Definition keyboard.h:231
KBD_KEY_NONE
No key.
Definition keyboard.h:197
KBD_KEY_PAD_4
Keypad 4 key.
Definition keyboard.h:288
KBD_KEY_RBRACKET
Right Bracket key.
Definition keyboard.h:245
KBD_KEY_F3
F3 key.
Definition keyboard.h:256
KBD_KEY_F1
F1 key.
Definition keyboard.h:254
KBD_KEY_F
F key.
Definition keyboard.h:206
KBD_KEY_1
1 key
Definition keyboard.h:227
KBD_KEY_PAD_PERIOD
Keypad Period key.
Definition keyboard.h:295
KBD_KEY_A
A key.
Definition keyboard.h:201
KBD_KEY_UP
Up Arrow key.
Definition keyboard.h:278
KBD_KEY_U
U key.
Definition keyboard.h:221
KBD_KEY_PAD_8
Keypad 8 key.
Definition keyboard.h:292
KBD_KEY_4
4 key
Definition keyboard.h:230
KBD_KEY_F2
F2 key.
Definition keyboard.h:255
KBD_KEY_PAD_7
Keypad 7 key.
Definition keyboard.h:291
KBD_KEY_P
P key.
Definition keyboard.h:216
KBD_KEY_HOME
Home key.
Definition keyboard.h:270
KBD_KEY_BACKSPACE
Backspace key.
Definition keyboard.h:239
KBD_KEY_ENTER
Enter key.
Definition keyboard.h:237
KBD_KEY_ERR2
Unknown error.
Definition keyboard.h:199
KBD_KEY_Q
Q key.
Definition keyboard.h:217
KBD_KEY_LBRACKET
Left Bracket key.
Definition keyboard.h:244
KBD_KEY_DOWN
Down Arrow key.
Definition keyboard.h:277
KBD_KEY_V
V key.
Definition keyboard.h:222
KBD_KEY_7
7 key
Definition keyboard.h:233
KBD_KEY_INSERT
Insert key.
Definition keyboard.h:269
KBD_KEY_PAD_MULTIPLY
Keypad Multiply key.
Definition keyboard.h:281
KBD_KEY_F8
F8 key.
Definition keyboard.h:261
KBD_KEY_Y
Y key.
Definition keyboard.h:225
KBD_KEY_F7
F7 key.
Definition keyboard.h:260
KBD_KEY_X
X key.
Definition keyboard.h:224
KBD_KEY_PAD_ENTER
Keypad Enter key.
Definition keyboard.h:284
KBD_KEY_CAPSLOCK
Caps Lock key.
Definition keyboard.h:253
KBD_KEY_SLASH
Slash key.
Definition keyboard.h:252
Maple Bus driver interface.
Macros to help dealing with register fields.
Keyboard raw condition structure.
Definition keyboard.h:356
kbd_mods_t modifiers
Bitmask of set modifiers.
Definition keyboard.h:357
kbd_leds_t leds
Bitmask of set LEDs.
Definition keyboard.h:358
Keyboard status structure.
Definition keyboard.h:369
kbd_mods_t last_modifiers
Definition keyboard.h:386
kbd_cond_t cond
The latest raw condition of the keyboard.
Definition keyboard.h:371
kbd_region_t region
Keyboard type/region.
Definition keyboard.h:390
One maple device.
Definition maple.h:271
Common integer types.
Keyboard LEDs.
Definition keyboard.h:156
uint8_t raw
Packed 8-bit unsigned integer of bitflags.
Definition keyboard.h:168
uint8_t kana
Kana LED.
Definition keyboard.h:164
uint8_t caps_lock
Caps Lock LED.
Definition keyboard.h:160
uint8_t scroll_lock
Scroll Lock LED.
Definition keyboard.h:161
uint8_t power
Power LED.
Definition keyboard.h:165
uint8_t unknown2
Unknown LED 2.
Definition keyboard.h:163
uint8_t num_lock
Num Lock LED.
Definition keyboard.h:159
uint8_t unknown1
Unknown LED 1.
Definition keyboard.h:162
uint8_t shift
Shift LED.
Definition keyboard.h:166
Modifier Keys.
Definition keyboard.h:100
uint8_t rshift
Right Shift key.
Definition keyboard.h:108
uint8_t lctrl
Left Control key.
Definition keyboard.h:103
uint8_t lalt
Left Alternate key.
Definition keyboard.h:105
uint8_t lshift
Left Shift key.
Definition keyboard.h:104
uint8_t s2
S2 key.
Definition keyboard.h:110
uint8_t s1
S1 key.
Definition keyboard.h:106
uint8_t rctrl
Right Control key.
Definition keyboard.h:107
uint8_t ralt
Right Alternate key.
Definition keyboard.h:109
uint8_t raw
Packed 8-bit unsigned integer of bitflags.
Definition keyboard.h:112