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.

191 lines
10 KiB

  1. # Adding Default Keymaps to QMK Configurator :id=adding-default-keymaps
  2. This page covers how to add a default keymap for a keyboard to QMK Configurator.
  3. ## Technical Information :id=technical-information
  4. QMK Configurator uses JSON as its native file format for keymaps. As much as possible, these should be kept such that they behave the same as running `make <keyboard>:default` from `qmk_firmware`.
  5. Keymaps in this directory require four key-value pairs:
  6. * `keyboard` (string)
  7. * This is the name of the keyboard, the same as would be used when running a compile job through `make` (e.g. `make 1upkeyboards/1up60rgb:default`).
  8. * `keymap` (string)
  9. * Should be set to `default`.
  10. * `layout` (string)
  11. * This is the layout macro used by the default keymap.
  12. * `layers` (array)
  13. * The keymap itself. This key should contain one array per layer, which themselves should contain the keycodes that make up that layer.
  14. Additionally, most keymaps contain a `commit` key. This key is not consumed by the API that back-stops QMK Configurator, but is used by Configurator's maintainers to tell which version of a keymap was used to create the JSON keymap in this repository. The value is the SHA of the last commit to modify a board's default `keymap.c` in the `qmk_firmware` repository. The SHA is found by checking out [the `master` branch of the `qmk/qmk_firmware` repository](https://github.com/qmk/qmk_firmware/tree/master/) and running `git log -1 --pretty=oneline -- keyboards/<keyboard>/keymaps/default/keymap.c` (use `keymap.json` if the keyboard in question has this file instead), which should return something similar to:
  15. ```
  16. f14629ed1cd7c7ec9089604d64f29a99981558e8 Remove/migrate action_get_macro()s from default keymaps (#5625)
  17. ```
  18. In this example, `f14629ed1cd7c7ec9089604d64f29a99981558e8` is the value that should be used for `commit`.
  19. ## Example :id=example
  20. If one wished to add a default keymap for the H87a by Hineybush, one would run the `git log` command above against the H87a's default keymap in `qmk_firmware`:
  21. ```
  22. user ~/qmk_firmware (master)
  23. $ git log -1 --pretty=oneline master -- keyboards/hineybush/h87a/keymaps/default/keymap.c
  24. ef8878fba5d3786e3f9c66436da63a560cd36ac9 Hineybush h87a lock indicators (#8237)
  25. ```
  26. Now that we have the commit hash, we need the keymap (edited for readability):
  27. ```c
  28. ...
  29. #include QMK_KEYBOARD_H
  30. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  31. [0] = LAYOUT_all(
  32. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SCRL, KC_PAUS,
  33. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_BSPC, KC_INS, KC_HOME, KC_PGUP,
  34. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN,
  35. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT,
  36. KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_TRNS, KC_UP,
  37. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_RGUI, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT),
  38. [1] = LAYOUT_all(
  39. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG, RGB_MOD, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, RGB_VAD, RGB_VAI, BL_TOGG, BL_DOWN, BL_UP,
  40. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU,
  41. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, QK_BOOT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_MNXT, KC_VOLD,
  42. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  43. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  44. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS),
  45. };
  46. ```
  47. The default keymap uses the `LAYOUT_all` macro, so that will be the value of the `layout` key. Compiled to a QMK Configurator JSON keymap, our resulting file should be:
  48. ```json
  49. {
  50. "keyboard": "hineybush/h87a",
  51. "keymap": "default",
  52. "commit": "ef8878fba5d3786e3f9c66436da63a560cd36ac9",
  53. "layout": "LAYOUT_all",
  54. "layers": [
  55. [
  56. "KC_ESC", "KC_F1", "KC_F2", "KC_F3", "KC_F4", "KC_F5", "KC_F6", "KC_F7", "KC_F8", "KC_F9", "KC_F10", "KC_F11", "KC_F12", "KC_PSCR", "KC_SCRL", "KC_PAUS",
  57. "KC_GRV", "KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", "KC_MINS", "KC_EQL", "KC_BSPC", "KC_BSPC", "KC_INS", "KC_HOME", "KC_PGUP",
  58. "KC_TAB", "KC_Q", "KC_W", "KC_E", "KC_R", "KC_T", "KC_Y", "KC_U", "KC_I", "KC_O", "KC_P", "KC_LBRC", "KC_RBRC", "KC_BSLS", "KC_DEL", "KC_END", "KC_PGDN",
  59. "KC_CAPS", "KC_A", "KC_S", "KC_D", "KC_F", "KC_G", "KC_H", "KC_J", "KC_K", "KC_L", "KC_SCLN", "KC_QUOT", "KC_NUHS", "KC_ENT",
  60. "KC_LSFT", "KC_NUBS", "KC_Z", "KC_X", "KC_C", "KC_V", "KC_B", "KC_N", "KC_M", "KC_COMM", "KC_DOT", "KC_SLSH", "KC_RSFT", "KC_TRNS", "KC_UP",
  61. "KC_LCTL", "KC_LGUI", "KC_LALT", "KC_SPC", "KC_RALT", "MO(1)", "KC_RGUI", "KC_RCTL", "KC_LEFT", "KC_DOWN", "KC_RGHT"
  62. ],
  63. [
  64. "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "RGB_TOG", "RGB_MOD", "RGB_HUD", "RGB_HUI", "RGB_SAD", "RGB_SAI", "RGB_VAD", "RGB_VAI", "BL_TOGG", "BL_DOWN", "BL_UP",
  65. "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_VOLU",
  66. "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "QK_BOOT", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_MPLY", "KC_MNXT", "KC_VOLD",
  67. "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS",
  68. "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS",
  69. "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS"
  70. ]
  71. ]
  72. }
  73. ```
  74. The white space in the `layers` arrays have no effect on the functionality of the keymap, but are used to make these files easier for humans to read.
  75. ## Caveats :id=caveats
  76. ### Layers can only be referenced by number :id=layer-references
  77. A common QMK convention is to name layers using a series of `#define`s, or an `enum` statement:
  78. ```c
  79. enum layer_names {
  80. _BASE,
  81. _MEDIA,
  82. _FN
  83. };
  84. ```
  85. This works in C, but for Configurator, you *must* use the layer's numeric index โ€“ `MO(_FN)` would need to be `MO(2)` in the above example.
  86. ### No support for custom code of any kind :id=custom-code
  87. Features that require adding functions to the keymap.c file, such as Tap Dance or Unicode, can not be compiled in Configurator **at all**. Even setting `TAP_DANCE_ENABLE = yes` in the `qmk_firmware` repository at the keyboard level will prevent Configurator from compiling **any** firmware for that keyboard. This is limited both by the API and the current spec of our JSON keymap format.
  88. ### Limited Support for Custom keycodes :id=custom-keycodes
  89. There is a way to support custom keycodes: if the logic for a custom keycode is implemented at the keyboard level instead of the keymap level in qmk_firmware, that keycode *can* be used in Configurator and it *will* compile and work. Instead of using the following in your `keymap.c`:
  90. ```c
  91. enum custom_keycodes {
  92. CUSTOM_1 = SAFE_RANGE,
  93. CUSTOM_2,
  94. CUSTOM_3
  95. };
  96. ...
  97. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  98. switch(keycode) {
  99. case CUSTOM_1:
  100. if (record->event.pressed) {
  101. SEND_STRING("This is custom keycode #1.");
  102. }
  103. return false;
  104. case CUSTOM_2:
  105. if (record->event.pressed) {
  106. SEND_STRING("This is custom keycode #2.");
  107. }
  108. return false;
  109. case CUSTOM_3:
  110. if (record->event.pressed) {
  111. SEND_STRING("This is custom keycode #3.");
  112. }
  113. return false;
  114. }
  115. return true;
  116. };
  117. ```
  118. ... add the keycode `enum` block to your keyboard's header file (`<keyboard>.h`) as follows (note that the `enum` is named `keyboard_keycodes` here):
  119. ```c
  120. enum keyboard_keycodes {
  121. CUSTOM_1 = QK_KB_0,
  122. CUSTOM_2,
  123. CUSTOM_3,
  124. };
  125. ```
  126. ... then the logic to your `<keyboard>.c` through `process_record_kb()`:
  127. ```c
  128. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  129. switch(keycode) {
  130. case CUSTOM_1:
  131. if (record->event.pressed) {
  132. SEND_STRING("This is custom keycode #1.");
  133. }
  134. return false;
  135. case CUSTOM_2:
  136. if (record->event.pressed) {
  137. SEND_STRING("This is custom keycode #2.");
  138. }
  139. return false;
  140. case CUSTOM_3:
  141. if (record->event.pressed) {
  142. SEND_STRING("This is custom keycode #3.");
  143. }
  144. return false;
  145. }
  146. return process_record_user(keycode, record);
  147. };
  148. ```
  149. Note the call to `process_record_user()` at the end.
  150. ## Additional Reading :id=additional-reading
  151. For QMK Configurator to support your keyboard, your keyboard must be present in the `master` branch of the `qmk_firmware` repository. For instructions on this, please see [Supporting Your Keyboard in QMK Configurator](reference_configurator_support.md).