You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
11 KiB

  1. # Quantum Keycodes
  2. All keycodes within quantum are numbers between `0x0000` and `0xFFFF`. Within your `keymap.c` it may look like you have functions and other special cases, but ultimately the C preprocessor will translate those into a single 4 byte integer. QMK has reserved `0x0000` through `0x00FF` for standard keycodes. These are keycodes such as `KC_A`, `KC_1`, and `KC_LCTL`, which are basic keys defined in the USB HID specification.
  3. On this page we have documented keycodes between `0x00FF` and `0xFFFF` which are used to implement advanced quantum features. If you define your own custom keycodes they will be put into this range as well. Keycodes above `0x00FF` may not be used with any of the mod/layer-tap keys listed
  4. ## QMK keycodes
  5. |Name|Description|
  6. |----|-----------|
  7. |`RESET`|Put the keyboard into DFU mode for flashing|
  8. |`DEBUG`|Toggles debug mode|
  9. |`KC_GESC`/`GRAVE_ESC`|Acts as escape when pressed normally but when pressed with Shift or GUI will send a `~`|
  10. |`KC_LSPO`|Left shift when held, open paranthesis when tapped|
  11. |`KC_RSPC`|Right shift when held, close paranthesis when tapped|
  12. |`KC_LEAD`|The [leader key](leader_key.md)|
  13. |`FUNC(n)`/`F(n)`|Call `fn_action(n)`|
  14. |`M(n)`|to call macro n|
  15. |`MACROTAP(n)`|to macro-tap n idk FIXME|
  16. ## Bootmagic Keycodes
  17. Shortcuts for bootmagic options (these work even when bootmagic is off.)
  18. |Name|Description|
  19. |----|-----------|
  20. |`MAGIC_SWAP_CONTROL_CAPSLOCK`|Swap Capslock and Left Control|
  21. |`MAGIC_CAPSLOCK_TO_CONTROL`|Treat Capslock like a Control Key|
  22. |`MAGIC_SWAP_LALT_LGUI`|Swap the left Alt and GUI keys|
  23. |`MAGIC_SWAP_RALT_RGUI`|Swap the right Alt and GUI keys|
  24. |`MAGIC_NO_GUI`|Disable the GUI key|
  25. |`MAGIC_SWAP_GRAVE_ESC`|Swap the Grave and Esc key.|
  26. |`MAGIC_SWAP_BACKSLASH_BACKSPACE`|Swap backslack and backspace|
  27. |`MAGIC_HOST_NKRO`|Force NKRO on|
  28. |`MAGIC_SWAP_ALT_GUI`/`AG_SWAP`|Swap Alt and Gui on both sides|
  29. |`MAGIC_UNSWAP_CONTROL_CAPSLOCK`|Disable the Control/Capslock swap|
  30. |`MAGIC_UNCAPSLOCK_TO_CONTROL`|Disable treating Capslock like Control |
  31. |`MAGIC_UNSWAP_LALT_LGUI`|Disable Left Alt and GUI switching|
  32. |`MAGIC_UNSWAP_RALT_RGUI`|Disable Right Alt and GUI switching|
  33. |`MAGIC_UNNO_GUI`|Enable the GUI key |
  34. |`MAGIC_UNSWAP_GRAVE_ESC`|Disable the Grave/Esc swap |
  35. |`MAGIC_UNSWAP_BACKSLASH_BACKSPACE`|Disable the backslash/backspace swap|
  36. |`MAGIC_UNHOST_NKRO`|Force NKRO off|
  37. |`MAGIC_UNSWAP_ALT_GUI`/`AG_NORM`|Disable the Alt/GUI switching|
  38. |`MAGIC_TOGGLE_NKRO`|Turn NKRO on or off|
  39. <!-- FIXME: this formatting needs work
  40. ## Audio
  41. ```c
  42. #ifdef AUDIO_ENABLE
  43. AU_ON,
  44. AU_OFF,
  45. AU_TOG,
  46. #ifdef FAUXCLICKY_ENABLE
  47. FC_ON,
  48. FC_OFF,
  49. FC_TOG,
  50. #endif
  51. // Music mode on/off/toggle
  52. MU_ON,
  53. MU_OFF,
  54. MU_TOG,
  55. // Music voice iterate
  56. MUV_IN,
  57. MUV_DE,
  58. #endif
  59. ```
  60. ### Midi
  61. #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  62. MI_ON, // send midi notes when music mode is enabled
  63. MI_OFF, // don't send midi notes when music mode is enabled
  64. #endif
  65. MIDI_TONE_MIN,
  66. MIDI_TONE_MAX
  67. MI_C = MIDI_TONE_MIN,
  68. MI_Cs,
  69. MI_Db = MI_Cs,
  70. MI_D,
  71. MI_Ds,
  72. MI_Eb = MI_Ds,
  73. MI_E,
  74. MI_F,
  75. MI_Fs,
  76. MI_Gb = MI_Fs,
  77. MI_G,
  78. MI_Gs,
  79. MI_Ab = MI_Gs,
  80. MI_A,
  81. MI_As,
  82. MI_Bb = MI_As,
  83. MI_B,
  84. MIDI_TONE_KEYCODE_OCTAVES > 1
  85. where x = 1-5:
  86. MI_C_x,
  87. MI_Cs_x,
  88. MI_Db_x = MI_Cs_x,
  89. MI_D_x,
  90. MI_Ds_x,
  91. MI_Eb_x = MI_Ds_x,
  92. MI_E_x,
  93. MI_F_x,
  94. MI_Fs_x,
  95. MI_Gb_x = MI_Fs_x,
  96. MI_G_x,
  97. MI_Gs_x,
  98. MI_Ab_x = MI_Gs_x,
  99. MI_A_x,
  100. MI_As_x,
  101. MI_Bb_x = MI_As_x,
  102. MI_B_x,
  103. MI_OCT_Nx 1-2
  104. MI_OCT_x 0-7
  105. MIDI_OCTAVE_MIN = MI_OCT_N2,
  106. MIDI_OCTAVE_MAX = MI_OCT_7,
  107. MI_OCTD, // octave down
  108. MI_OCTU, // octave up
  109. MI_TRNS_Nx 1-6
  110. MI_TRNS_x 0-6
  111. MIDI_TRANSPOSE_MIN = MI_TRNS_N6,
  112. MIDI_TRANSPOSE_MAX = MI_TRNS_6,
  113. MI_TRNSD, // transpose down
  114. MI_TRNSU, // transpose up
  115. MI_VEL_x 1-10
  116. MIDI_VELOCITY_MIN = MI_VEL_1,
  117. MIDI_VELOCITY_MAX = MI_VEL_9,
  118. MI_VELD, // velocity down
  119. MI_VELU, // velocity up
  120. MI_CHx 1-16
  121. MIDI_CHANNEL_MIN = MI_CH1
  122. MIDI_CHANNEL_MAX = MI_CH16,
  123. MI_CHD, // previous channel
  124. MI_CHU, // next channel
  125. MI_ALLOFF, // all notes off
  126. MI_SUS, // sustain
  127. MI_PORT, // portamento
  128. MI_SOST, // sostenuto
  129. MI_SOFT, // soft pedal
  130. MI_LEG, // legato
  131. MI_MOD, // modulation
  132. MI_MODSD, // decrease modulation speed
  133. MI_MODSU, // increase modulation speed
  134. #endif // MIDI_ADVANCED
  135. -->
  136. ## Backlight
  137. These keycodes control the backlight. Most keyboards use this for single color in-switch lighting.
  138. |Name|Description|
  139. |----|-----------|
  140. |`BL_x`|Set a specific backlight level between 0-9|
  141. |`BL_ON`|An alias for `BL_9`|
  142. |`BL_OFF`|An alias for `BL_0`|
  143. |`BL_DEC`|Turn the backlight level down by 1|
  144. |`BL_INC`|Turn the backlight level up by 1|
  145. |`BL_TOGG`|Toggle the backlight on or off|
  146. |`BL_STEP`|Step through backlight levels, wrapping around to 0 when you reach the top.|
  147. ## RGBLIGHT WS2818 LEDs
  148. This controls the `RGBLIGHT` functionality. Most keyboards use WS2812 (and compatible) LEDs for underlight or case lighting.
  149. |Name|Description|
  150. |----|-----------|
  151. |`RGB_TOG`|toggle on/off|
  152. |`RGB_MOD`|cycle through modes|
  153. |`RGB_HUI`|hue increase|
  154. |`RGB_HUD`|hue decrease|
  155. |`RGB_SAI`|saturation increase|
  156. |`RGB_SAD`|saturation decrease|
  157. |`RGB_VAI`|value increase|
  158. |`RGB_VAD`|value decrease|
  159. ## Thermal Printer (experimental)
  160. |Name|Description|
  161. |----|-----------|
  162. |`PRINT_ON`|Start printing everything the user types|
  163. |`PRINT_OFF`|Stop printing everything the user types|
  164. ## Keyboard output selection
  165. This is used when multiple keyboard outputs can be selected. Currently this only allows for switching between USB and Bluetooth on keyboards that support both.
  166. |Name|Description|
  167. |----|-----------|
  168. |`OUT_AUTO`|auto mode|
  169. |`OUT_USB`|usb only|
  170. |`OUT_BT`|bluetooth (when `BLUETOOTH_ENABLE`)|
  171. ## Modifiers
  172. These are special keycodes that simulate pressing several modifiers at once.
  173. |Name|Description|
  174. |----|-----------|
  175. |`KC_HYPR`|Hold down LCTL + LSFT + LALT + LGUI|
  176. |`KC_MEH`|Hold down LCTL + LSFT + LALT|
  177. /* FIXME: Should we have these in QMK too?
  178. * |`KC_LCAG`|`LCTL` + `LALT` + `LGUI`|
  179. * |`KC_ALTG`|`RCTL` + `RALT`|
  180. * |`KC_SCMD`/`KC_SWIN`|`LGUI` + `LSFT`|
  181. * |`KC_LCA`|`LCTL` + `LALT`|
  182. */
  183. ### Modifiers with keys
  184. |Name|Description|
  185. |----|-----------|
  186. |`LCTL(kc)`|`LCTL` + `kc`|
  187. |`LSFT(kc)`/`S(kc)`|`LSFT` + `kc`|
  188. |`LALT(kc)`|`LALT` + `kc`|
  189. |`LGUI(kc)`|`LGUI` + `kc`|
  190. |`RCTL(kc)`|`RCTL` + `kc`|
  191. |`RSFT(kc)`|`RSFT` + `kc`|
  192. |`RALT(kc)`|`RALT` + `kc`|
  193. |`RGUI(kc)`|`RGUI` + `kc`|
  194. |`HYPR(kc)`|`LCTL` + `LSFT` + `LALT` + `LGUI` + `kc`|
  195. |`MEH(kc)`|`LCTL` + `LSFT` + `LALT` + `kc`|
  196. |`LCAG(kc)`|`LCTL` + `LALT` + `LGUI` + `kc`|
  197. |`ALTG(kc)`|`RCTL` + `RALT` + `kc`|
  198. |`SCMD(kc)`/`SWIN(kc)`|`LGUI` + `LSFT` + `kc`|
  199. |`LCA(kc)`|`LCTL` + `LALT` + `kc`|
  200. ### One Shot Keys
  201. Most modifiers work by being held down while you push another key. You can use `OSM()` to setup a "One Shot" modifier. When you tap a one shot mod it will remain is a pressed state until you press another key.
  202. To specify a your modifier you need to pass the `MOD` form of the key. For example, if you want to setup a One Shot Control you would use `OSM(MOD_LCTL)`.
  203. |Name|Description|
  204. |----|-----------|
  205. |`OSM(mod)`|use mod for one keypress|
  206. |`OSL(layer)`|switch to layer for one keypress|
  207. ### Mod-tap keys
  208. These keycodes will press the mod(s) when held, and the key when tapped. They only work with [basic keycodes](basic_keycodes.md).
  209. |Name|Description|
  210. |----|-----------|
  211. |`CTL_T(kc)`/`LCTL_T(kc)`|`LCTL` when held, `kc` when tapped|
  212. |`RCTL_T(kc)`|`RCTL` when held, `kc` when tapped|
  213. |`SFT_T(kc)`/`LSFT_T(kc)`|`LSFT` when held, `kc` when tapped|
  214. |`RSFT_T(kc)`|`RSFT` when held, `kc` when tapped|
  215. |`ALT_T(kc)`/`LALT_T(kc)`|`LALT` when held, `kc` when tapped|
  216. |`RALT_T(kc)`/`ALGR_T(kc)`|`RALT` when held, `kc` when tapped|
  217. |`GUI_T(kc)`/`LGUI_T(kc)`|`LGUI` when held, `kc` when tapped|
  218. |`RGUI_T(kc)`|`RGUI` when held, `kc` when tapped|
  219. |`C_S_T(kc)`|`LCTL` + `LSFT` when held, `kc` when tapped|
  220. |`MEH_T(kc)`|`LCTL` + `LSFT` + `LALT` when held, `kc` when tapped|
  221. |`LCAG_T(kc)`|`LCTL` + `LALT` + `LGUI` when held, `kc` when tapped|
  222. |`RCAG_T(kc)`|`RCTL` + `RALT` + `RGUI` when held, `kc` when tapped|
  223. |`ALL_T(kc)`|`LCTL` + `LSFT` + `LALT` + `LGUI` when held, `kc` when tapped [more info](http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/)|
  224. |`SCMD_T(kc)`/`SWIN_T(kc)`|`LGUI` + `LSFT` when held, `kc` when tapped|
  225. |`LCA_T(kc)`|`LCTL` + `LALT` when held, `kc` when tapped|
  226. ## US ANSI Shifted symbols
  227. These keycodes correspond to characters that are "shifted" on a standard US ANSI keyboards. They do not have dedicated keycodes but are instead typed by holding down shift and then sending a keycode.
  228. It's important to remember that all of these keycodes send a left shift - this may cause unintended actions if unaccounted for. The short code is preferred in most situations.
  229. |Short Name|Long Name|Description|
  230. |----------|---------|-----------|
  231. |`KC_TILD`|`KC_TILDE`|tilde `~`|
  232. |`KC_EXLM`|`KC_EXCLAIM`|exclamation mark `!`|
  233. |`KC_AT`||at sign `@`|
  234. |`KC_HASH`||hash sign `#`|
  235. |`KC_DLR`|`KC_DOLLAR`|dollar sign `$`|
  236. |`KC_PERC`|`KC_PERCENT`|percent sign `%`|
  237. |`KC_CIRC`|`KC_CIRCUMFLEX`|circumflex `^`|
  238. |`KC_AMPR`|`KC_AMPERSAND`|ampersand `&`|
  239. |`KC_ASTR`|`KC_ASTERISK`|asterisk `*`|
  240. |`KC_LPRN`|`KC_LEFT_PAREN`|left parenthesis `(`|
  241. |`KC_RPRN`|`KC_RIGHT_PAREN`|right parenthesis `)`|
  242. |`KC_UNDS`|`KC_UNDERSCORE`|underscore `_`|
  243. |`KC_PLUS`||plus sign `+`|
  244. |`KC_LCBR`|`KC_LEFT_CURLY_BRACE`|left curly brace `{`|
  245. |`KC_RCBR`|`KC_RIGHT_CURLY_BRACE`|right curly brace `}`|
  246. |`KC_LT`/`KC_LABK`|`KC_LEFT_ANGLE_BRACKET`|left angle bracket `<`|
  247. |`KC_GT`/`KC_RABK`|`KC_RIGHT_ANGLE_BRACKET`|right angle bracket `>`|
  248. |`KC_COLN`|`KC_COLON`|colon `:`|
  249. |`KC_PIPE`||pipe `\|`|
  250. |`KC_QUES`|`KC_QUESTION`|question mark `?`|
  251. |`KC_DQT`/`KC_DQUO`|`KC_DOUBLE_QUOTE`|double quote `"`|
  252. ## Layer Changes
  253. These are keycodes that can be used to change the current layer.
  254. |Name|Description|
  255. |----|-----------|
  256. |`LT(layer, kc)`|turn on layer (0-15) when held, kc ([basic keycodes](basic_keycodes.md)) when tapped|
  257. |`TO(layer)`|turn on layer when depressed|
  258. |`MO(layer)`|momentarily turn on layer when depressed (requires `KC_TRNS` on destination layer)|
  259. |`DF(layer)`|sets the base (default) layer|
  260. |`TG(layer)`|toggle layer on/off|
  261. |`TT(layer)`|tap toggle? idk FIXME|
  262. |`OSL(layer)`|switch to layer for one keycode|
  263. ## Unicode
  264. These keycodes can be used in conjuction with the [Unicode](unicode_and_additional_language_support.md) support.
  265. |`UNICODE(n)`/`UC(n)`|if `UNICODE_ENABLE`, this will send characters up to `0x7FFF`|
  266. |`X(n)`|if `UNICODEMAP_ENABLE`, also sends unicode via a different method|
  267. # `SAFE_RANGE`, or safely defining custom keycodes
  268. Sometimes you want to define your own custom keycodes to make your keymap easier to read. QMK provides `SAFE_RANGE` to help you do that. `SAFE_RANGE` is the first available keycode in the `0x0000`-`0xFFFF` range and you can use it when creating your own custom keycode enum:
  269. ```
  270. enum my_keycodes {
  271. FOO = SAFE_RANGE,
  272. BAR
  273. };
  274. ```
  275. You can then use `process_record_user()` to do something with your keycode:
  276. ```
  277. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  278. switch (keycode) {
  279. case FOO:
  280. // Do something here
  281. break;
  282. case BAR:
  283. // Do something here
  284. break;
  285. }
  286. }
  287. ```