brlapi_keycodes.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * libbrlapi - A library providing access to braille terminals for applications.
  3. *
  4. * Copyright (C) 2002-2020 by
  5. * Samuel Thibault <Samuel.Thibault@ens-lyon.org>
  6. * Sébastien Hinderer <Sebastien.Hinderer@ens-lyon.org>
  7. *
  8. * libbrlapi comes with ABSOLUTELY NO WARRANTY.
  9. *
  10. * This is free software, placed under the terms of the
  11. * GNU Lesser General Public License, as published by the Free Software
  12. * Foundation; either version 2.1 of the License, or (at your option) any
  13. * later version. Please see the file LICENSE-LGPL for details.
  14. *
  15. * Web Page: http://brltty.app/
  16. *
  17. * This software is maintained by Dave Mielke <dave@mielke.cc>.
  18. */
  19. /** \file
  20. */
  21. #ifndef BRLAPI_INCLUDED_KEYCODES
  22. #define BRLAPI_INCLUDED_KEYCODES
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /* __cplusplus */
  26. /** \defgroup brlapi_keycodes Types and Defines for \e BrlAPI Key Codes
  27. *
  28. * Key codes are unsigned 64 bit integers. This 64-bit space is split into 3
  29. * parts:
  30. *
  31. * - bits 63-32 (BRLAPI_KEY_FLAGS_MASK), flags: bits 39-32 are standard X
  32. * modifiers (shift, control, meta, ...). Other flags are used for some commands,
  33. * see documentation of BRLAPI_KEY_FLG_* for their respective uses.
  34. * - bits 31-29 (BRLAPI_KEY_TYPE_MASK), key type: either BRLAPI_KEY_TYPE_CMD for
  35. * braille commands, or BRLAPI_KEY_TYPE_SYM for standard X keysyms.
  36. * - bits 28-0 (BRLAPI_KEY_CODE_MASK), key code: for braille commands, see
  37. * BRLAPI_KEY_CMD_* ; for standard X keysyms, this is the keysym value, see
  38. * X11 documentation, a complete list is probably available on your system in
  39. * /usr/include/X11/keysymdef.h
  40. *
  41. * The third part is itself split into two parts: a command number and a command
  42. * value. The relative sizes of these parts vary according to the key type.
  43. *
  44. * For a braille command, bits 28-16 (BRLAPI_KEY_CMD_BLK_MASK) hold the braille
  45. * command number, while bits 15-0 (BRLAPI_KEY_CMD_ARG_MASK) hold the command
  46. * value.
  47. *
  48. * For a X keysym, if it is a unicode keysym (0x1uvwxyz), then the command
  49. * number part is 0x1000000 and the value part is 0xuvwxyz. Else, the command
  50. * part is held by bits 28-8 and the value part is held by bits 7-0. This
  51. * permits to easily handle usual cases like 0x00xy (latin1), 0x01xy (latin2),
  52. * XK_Backspace (0xff08, backspace), XK_Tab (0xff09, tab), ...
  53. *
  54. * For instance, if key == 0x0000000020010008,
  55. * - (key & BRLAPI_KEY_TYPE_MASK) == BRLAPI_KEY_TYPE_CMD, so it's a braille
  56. * command
  57. * - (key & BRLAPI_KEY_CMD_BLK_MASK) == BRLAPI_KEY_CMD_ROUTE, so it's the
  58. * braille route command.
  59. * - (key & BRLAPI_KEY_CMD_ARG_MASK) == 8, so the highlighted cell is the 9th
  60. * one (cells are numbered from 0)
  61. * - (key & BRLAPI_KEY_FLAGS_MASK) == 0, so no modifier key was pressed during
  62. * the command, and no particular flag applies to the command.
  63. *
  64. * if key == 0x000000010000FF09,
  65. * - (key & BRLAPI_KEY_TYPE_MASK) == BRLAPI_KEY_TYPE_SYM, so it's a keysym
  66. * - (key & BRLAPI_KEY_CODE_MASK) == XK_Tab, so it's the tab key.
  67. * BRLAPI_KEY_SYM_TAB can also be used here, as well as a few other
  68. * BRLAPI_KEY_SYM_* constants which are provided to avoid having to include
  69. * X11/keysymdef.h
  70. * - (key & BRLAPI_KEY_FLAGS_MASK) == BRLAPI_KEY_FLG_SHIFT, so the shift
  71. * modifier was pressed during the command.
  72. *
  73. * in the X11 standard some keysyms are directly unicode, for instance if
  74. * key == 0x0000000001001EA0,
  75. * - (key & BRLAPI_KEY_TYPE_MASK) == BRLAPI_KEY_TYPE_SYM, so it's a keysym
  76. * - (key & BRLAPI_KEY_SYM_UNICODE) != 0 so it's a unicode keysym, whose value
  77. * is key & (BRLAPI_KEY_SYM_UNICODE-1). Of course, one can also consider
  78. * (key & BRLAPI_KEY_CODE_MASK) == XK_Abelowdot
  79. * - (key & BRLAPI_KEY_FLAGS_MASK) == 0, so no modifier key was pressed during
  80. * the command, and no particular flag applies to the command.
  81. *
  82. * The brlapi_expandKeyCode() function may be used for splitting key codes into
  83. * these parts.
  84. * @{
  85. */
  86. typedef uint64_t brlapi_keyCode_t;
  87. /** Define a brlapi_keyCode_t constant */
  88. #define BRLAPI_KEYCODE_C(value) UINT64_C(value)
  89. /** Hexadecimal print format for brlapi_keyCode_t */
  90. #define BRLAPI_PRIxKEYCODE PRIx64
  91. /** Unsigned decimal print format for brlapi_keyCode_t */
  92. #define BRLAPI_PRIuKEYCODE PRIu64
  93. /** Brlapi_keyCode_t's biggest value
  94. *
  95. * As defined in \c <stdint.h> */
  96. #define BRLAPI_KEY_MAX UINT64_C(0XFFFFFFFFFFFFFFFF)
  97. /**
  98. * Mask for flags of brlapi_keyCode_t
  99. */
  100. #define BRLAPI_KEY_FLAGS_MASK UINT64_C(0XFFFFFFFF00000000)
  101. /** Shift for flags of brlapi_keyCode_t */
  102. #define BRLAPI_KEY_FLAGS_SHIFT 32
  103. #define BRLAPI_KEY_FLG(v) ((brlapi_keyCode_t)(v) << BRLAPI_KEY_FLAGS_SHIFT)
  104. /** Standard X modifiers */
  105. /** Mod1 modifier (AKA meta) */
  106. #define BRLAPI_KEY_FLG_MOD1 BRLAPI_KEY_FLG(0x00000008)
  107. /** Mod2 modifier (usually numlock) */
  108. #define BRLAPI_KEY_FLG_MOD2 BRLAPI_KEY_FLG(0x00000010)
  109. /** Mod3 modifier */
  110. #define BRLAPI_KEY_FLG_MOD3 BRLAPI_KEY_FLG(0x00000020)
  111. /** Mod4 modifier */
  112. #define BRLAPI_KEY_FLG_MOD4 BRLAPI_KEY_FLG(0x00000040)
  113. /** Mod5 modifier (usually Alt-Gr) */
  114. #define BRLAPI_KEY_FLG_MOD5 BRLAPI_KEY_FLG(0x00000080)
  115. /**
  116. * Mask for type of brlapi_keyCode_t
  117. */
  118. #define BRLAPI_KEY_TYPE_MASK UINT64_C(0X00000000E0000000)
  119. /** Shift for type of brlapi_keyCode_t */
  120. #define BRLAPI_KEY_TYPE_SHIFT 29
  121. /** Braille command brlapi_keyCode_t */
  122. #define BRLAPI_KEY_TYPE_CMD UINT64_C(0X0000000020000000)
  123. /** X Keysym brlapi_keyCode_t */
  124. #define BRLAPI_KEY_TYPE_SYM UINT64_C(0X0000000000000000)
  125. /**
  126. * Mask for code of brlapi_keyCode_t
  127. */
  128. #define BRLAPI_KEY_CODE_MASK UINT64_C(0X000000001FFFFFFF)
  129. /** Shift for code of brlapi_keyCode_t */
  130. #define BRLAPI_KEY_CODE_SHIFT 0
  131. /** Mask for braille command type */
  132. #define BRLAPI_KEY_CMD_BLK_MASK UINT64_C(0X1FFF0000)
  133. /** Shift for braille command type */
  134. #define BRLAPI_KEY_CMD_BLK_SHIFT 16
  135. /** Mask for braille command value */
  136. #define BRLAPI_KEY_CMD_ARG_MASK UINT64_C(0X0000FFFF)
  137. /** Shift for braille command value */
  138. #define BRLAPI_KEY_CMD_ARG_SHIFT 0
  139. #define BRLAPI_KEY_CMD(v) ((v) << BRLAPI_KEY_CMD_BLK_SHIFT)
  140. /** Standard X keysyms */
  141. #define BRLAPI_KEY_SYM_BACKSPACE UINT64_C(0X0000FF08)
  142. #define BRLAPI_KEY_SYM_TAB UINT64_C(0X0000FF09)
  143. #define BRLAPI_KEY_SYM_LINEFEED UINT64_C(0X0000FF0D)
  144. #define BRLAPI_KEY_SYM_ESCAPE UINT64_C(0X0000FF1B)
  145. #define BRLAPI_KEY_SYM_HOME UINT64_C(0X0000FF50)
  146. #define BRLAPI_KEY_SYM_LEFT UINT64_C(0X0000FF51)
  147. #define BRLAPI_KEY_SYM_UP UINT64_C(0X0000FF52)
  148. #define BRLAPI_KEY_SYM_RIGHT UINT64_C(0X0000FF53)
  149. #define BRLAPI_KEY_SYM_DOWN UINT64_C(0X0000FF54)
  150. #define BRLAPI_KEY_SYM_PAGE_UP UINT64_C(0X0000FF55)
  151. #define BRLAPI_KEY_SYM_PAGE_DOWN UINT64_C(0X0000FF56)
  152. #define BRLAPI_KEY_SYM_END UINT64_C(0X0000FF57)
  153. #define BRLAPI_KEY_SYM_INSERT UINT64_C(0X0000FF63)
  154. #define BRLAPI_KEY_SYM_FUNCTION UINT64_C(0X0000FFBE)
  155. #define BRLAPI_KEY_SYM_DELETE UINT64_C(0X0000FFFF)
  156. #define BRLAPI_KEY_SYM_UNICODE UINT64_C(0X01000000)
  157. /**
  158. * Flag for a raw keycode press vs release
  159. *
  160. * When brlapi_enterTtyMode() has been called with a driver name,
  161. * brlapi_readKey() and brlapi_readKeyWithTimeout() will return
  162. * driver-specific key codes except for the common BRLAPI_DRV_KEY_PRESS flag
  163. * which indicates that it's a key press (as opposed to a release) event.
  164. */
  165. #define BRLAPI_DRV_KEY_PRESS BRLAPI_KEYCODE_C(0X8000000000000000)
  166. /** @} */
  167. #include "brlapi_constants.h"
  168. #ifdef __cplusplus
  169. }
  170. #endif /* __cplusplus */
  171. #endif /* BRLAPI_INCLUDED_KEYCODES */