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.

137 lines
5.7 KiB

  1. // Copyright (C) 2019, 2020 Keyboard.io, Inc
  2. // 2021 Antoine R. Dumont (@ardumont) <antoine.romain.dumont@gmail.com>
  3. //
  4. // this is the style you want to emulate.
  5. // This is the canonical layout file for the Quantum project. If you want to add another keyboard,
  6. #include QMK_KEYBOARD_H
  7. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  8. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  9. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  10. // entirely and just use numbers.
  11. enum layer_names {
  12. _QW,
  13. _RS,
  14. _LW,
  15. };
  16. // tap: z // hold: SHIFT
  17. #define Z_SFT SFT_T(KC_Z)
  18. // tap: / // hold: SHIFT
  19. #define SLSH_SFT SFT_T(KC_SLSH)
  20. // tap: ` // hold: SHIFT
  21. #define GRAVE_SFT SFT_T(KC_GRAVE)
  22. // tap: [ // hold: SHIFT
  23. #define RBRC_SFT SFT_T(KC_RBRC)
  24. // Layer movment
  25. #define FN0 MO(_RS) // move to layer 1 (L1)
  26. #define FN1 TG(_LW) // move to layer 2 (L2)
  27. #define FN2 TO(_QW) // move to layer 0 (L0)
  28. /*
  29. * q w e r t || y u i/tab o p
  30. * a s d f g || h j k l ;
  31. * z/sft x c v b ` || \ n m , . //sft
  32. * ctl esc super alt L1 spc || spc L1 alt - ' ctl
  33. */
  34. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  35. [_QW] = LAYOUT( /* Qwerty */
  36. KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P ,
  37. KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN ,
  38. Z_SFT, KC_X, KC_C, KC_V, KC_B, KC_GRAVE, KC_BSLS, KC_N, KC_M, KC_COMM, KC_DOT, SLSH_SFT,
  39. KC_LCTRL, KC_ESC, KC_LGUI, KC_LALT, KC_SPC, FN0, FN0, KC_SPC, KC_LALT, KC_MINS, KC_QUOT, KC_LCTRL
  40. ),
  41. /*
  42. * 1 2 3 4 5 || 6 7 8 9 0
  43. * ! @ # $ % || ^ & * ( )
  44. * `/sft ~ ? ? ? ~ || | + - / [ ]/sft
  45. * ctl esc super alt spc L2 || L2 spc alt = esc ctl
  46. */
  47. [_RS] = LAYOUT( /* [> RAISE <] */
  48. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 ,
  49. KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN ,
  50. GRAVE_SFT, KC_TILD, KC_NO, KC_NO, KC_NO, _______, _______, KC_PLUS, KC_MINS, KC_SLSH, KC_LBRC, RBRC_SFT,
  51. _______, _______, _______, _______, _______, FN1, FN1, _______, _______, KC_EQL, _______, _______
  52. ),
  53. /*
  54. * F1 F2 F3 F4 F5 || F6 F7 F8 F9 F10
  55. * __ __ __ __ F11 || F12 __ __ __ __
  56. * __ __ __ dbg rst eep-rst || __ __ __ __ __ __
  57. * ctl esc super alt __ L0 || L0 __ alt __ esc ctl
  58. */
  59. [_LW] = LAYOUT( /* [> LOWER <] */
  60. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10,
  61. KC_NO, KC_NO, KC_NO, KC_NO, KC_F11, KC_F12, KC_NO, KC_NO, KC_NO, KC_NO ,
  62. KC_NO, KC_NO, KC_NO, DEBUG, RESET, EEP_RST, _______, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO ,
  63. _______, _______, _______, _______, _______, FN2, FN2, _______, _______, KC_NO, KC_ESC, _______
  64. )
  65. };
  66. // Initialize variable holding the binary
  67. // representation of active modifiers.
  68. uint8_t mod_state;
  69. bool substitute_keycode(uint16_t keycode, keyrecord_t *record, uint8_t mod_state, uint16_t substitute_keycode) {
  70. /* Substitute keycode if condition matches */
  71. // Initialize a boolean variable that keeps track
  72. // of the delete key status: registered or not?
  73. static bool key_registered;
  74. // ctrl activated?
  75. if ((mod_state & MOD_BIT(KC_LCTRL)) == MOD_BIT(KC_LCTRL)) {
  76. if (record->event.pressed) {
  77. // No need to register KC_LCTRL because it's already active.
  78. unregister_code(KC_LCTRL);
  79. // Send substitute code
  80. register_code(substitute_keycode);
  81. // Update the boolean variable to reflect the status of the register
  82. key_registered = true;
  83. // Reapplying modifier state so that the held shift key(s)
  84. // still work even after having tapped the Backspace/Delete key.
  85. set_mods(mod_state);
  86. // Do not let QMK process the keycode further
  87. return false;
  88. } else {
  89. // In case substitude_keycode is still even after release of the key
  90. if (key_registered) {
  91. unregister_code(substitute_keycode);
  92. key_registered = false;
  93. // Do not let QMK process the keycode further
  94. return false;
  95. }
  96. }
  97. } else { // ctrl got released
  98. // In case substitude_keycode is still sent after release of the ctrl key
  99. if (key_registered) {
  100. unregister_code(substitute_keycode);
  101. key_registered = false;
  102. }
  103. }
  104. // Else, let QMK process the keycode as usual
  105. return true;
  106. }
  107. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  108. // Store the current modifier state in the variable for later reference
  109. mod_state = get_mods();
  110. switch (keycode) {
  111. case KC_I:
  112. return substitute_keycode(keycode, record, mod_state, KC_TAB);
  113. case KC_M:
  114. return substitute_keycode(keycode, record, mod_state, KC_ENTER);
  115. case KC_H:
  116. return substitute_keycode(keycode, record, mod_state, KC_BSPC);
  117. case KC_D:
  118. return substitute_keycode(keycode, record, mod_state, KC_DEL);
  119. case KC_N:
  120. return substitute_keycode(keycode, record, mod_state, KC_DOWN);
  121. case KC_P:
  122. return substitute_keycode(keycode, record, mod_state, KC_UP);
  123. }
  124. return true;
  125. };