keymap.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* Copyright 2022 Ryan Anderson <ryan@michonline.com>
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. /* layer constants */
  18. enum {
  19. DEF = 0,
  20. FUN,
  21. };
  22. enum custom_keycode {
  23. MACRO_CTRL_PAGE_UP = SAFE_RANGE,
  24. KC_MT_LCBRC,
  25. KC_MT_RCBRC,
  26. KC_MT_LPAR,
  27. KC_MT_RPAR,
  28. MACRO_KVM_1,
  29. MACRO_KVM_2,
  30. MACRO_KVM_3,
  31. MACRO_KVM_4,
  32. MACRO_KVM_TG,
  33. };
  34. // Work around limitations in mod-tapping
  35. static uint16_t space_cadet_control_timer = 0;
  36. static bool space_cadet_key_pressed_flag = false;
  37. // clang-format off
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39. [DEF] = LAYOUT(
  40. QK_BOOT , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , MACRO_CTRL_PAGE_UP,
  41. KC_GRV , KC_Q , KC_W , KC_E , KC_R , KC_T , RGB_MOD, MACRO_KVM_TG, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_EQL ,
  42. LCTL_T(KC_PGUP), KC_A , KC_S , KC_D , KC_F , KC_G , KC_TAB , KC_ENT , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT,
  43. KC_PGDN, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_ESC , KC_RALT, KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_MINS,
  44. LCTL_T(KC_LBRC), RCTL_T(KC_RBRC),
  45. KC_BSPC, KC_SPC ,
  46. KC_MT_LCBRC, KC_MT_RCBRC,
  47. KC_MT_LPAR, KC_MT_RPAR,
  48. MO(FUN), MO(FUN)
  49. ),
  50. [FUN] = LAYOUT(
  51. _______, KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 ,
  52. KC_TAB , _______, KC_MS_U, KC_WH_U, KC_BTN3, MACRO_KVM_1, RGB_TOG, KC_MPRV, KC_MNXT, KC_LCBR, KC_RCBR, KC_LBRC, KC_RBRC, KC_F12 ,
  53. KC_HOME, KC_MS_L, KC_MS_D, KC_MS_R, KC_BTN1, MACRO_KVM_2, RGB_SPI, KC_MPLY, KC_LEFT, KC_DOWN, KC_UP , KC_RGHT, _______, _______,
  54. KC_END , KC_PSCR, KC_INS , KC_WH_D, KC_BTN2, MACRO_KVM_4, RGB_SPD, _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, KC_BSLS, KC_PIPE,
  55. _______, _______,
  56. KC_DEL , KC_ENT ,
  57. _______, _______,
  58. _______, _______,
  59. _______, _______
  60. )
  61. };
  62. /* template for new layouts:
  63. LAYOUT(
  64. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  65. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  66. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  67. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  68. _______, _______,
  69. _______, _______,
  70. _______, _______,
  71. _______, _______,
  72. _______, _______
  73. )
  74. */
  75. // clang-format on
  76. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  77. if (record->event.pressed) {
  78. space_cadet_key_pressed_flag = true;
  79. }
  80. switch (keycode) {
  81. case MACRO_CTRL_PAGE_UP:
  82. if (record->event.pressed) {
  83. // send some data
  84. SEND_STRING(SS_LCTL(SS_TAP(X_PGUP)));
  85. } else {
  86. // when keycode MACRO_CTRL_PAGE_UP is pressed
  87. }
  88. break;
  89. // These next two cases duplicate mod-tap functionality by hand to
  90. // work around the lack of support for shifted/modded keys as
  91. // "tap" side of things.
  92. case KC_MT_LCBRC:
  93. if (record->event.pressed) {
  94. space_cadet_control_timer = timer_read();
  95. space_cadet_key_pressed_flag = false;
  96. register_mods(MOD_BIT(KC_LGUI));
  97. } else {
  98. unregister_mods(MOD_BIT(KC_LGUI));
  99. if (timer_elapsed(space_cadet_control_timer) < TAPPING_TERM && !space_cadet_key_pressed_flag) {
  100. tap_code16(LSFT(KC_LBRC));
  101. }
  102. }
  103. return false;
  104. break;
  105. case KC_MT_RCBRC:
  106. if (record->event.pressed) {
  107. space_cadet_control_timer = timer_read();
  108. space_cadet_key_pressed_flag = false;
  109. register_mods(MOD_BIT(KC_LALT));
  110. } else {
  111. unregister_mods(MOD_BIT(KC_LALT));
  112. if (timer_elapsed(space_cadet_control_timer) < TAPPING_TERM && !space_cadet_key_pressed_flag) {
  113. tap_code16(LSFT(KC_RBRC));
  114. }
  115. }
  116. return false;
  117. break;
  118. case KC_MT_LPAR:
  119. if (record->event.pressed) {
  120. space_cadet_control_timer = timer_read();
  121. space_cadet_key_pressed_flag = false;
  122. register_mods(MOD_BIT(KC_LSFT));
  123. } else {
  124. unregister_mods(MOD_BIT(KC_LSFT));
  125. if (timer_elapsed(space_cadet_control_timer) < TAPPING_TERM && !space_cadet_key_pressed_flag) {
  126. tap_code16(LSFT(KC_9));
  127. }
  128. }
  129. return false;
  130. break;
  131. case KC_MT_RPAR:
  132. if (record->event.pressed) {
  133. space_cadet_control_timer = timer_read();
  134. space_cadet_key_pressed_flag = false;
  135. register_mods(MOD_BIT(KC_RSFT));
  136. } else {
  137. unregister_mods(MOD_BIT(KC_RSFT));
  138. if (timer_elapsed(space_cadet_control_timer) < TAPPING_TERM && !space_cadet_key_pressed_flag) {
  139. tap_code16(LSFT(KC_0));
  140. }
  141. }
  142. return false;
  143. break;
  144. case MACRO_KVM_1:
  145. if (record->event.pressed) {
  146. tap_code(KC_SCRL);
  147. tap_code(KC_SCRL);
  148. tap_code(KC_1);
  149. }
  150. break;
  151. case MACRO_KVM_2:
  152. if (record->event.pressed) {
  153. tap_code(KC_SCRL);
  154. tap_code(KC_SCRL);
  155. tap_code(KC_2);
  156. }
  157. break;
  158. case MACRO_KVM_3:
  159. if (record->event.pressed) {
  160. tap_code(KC_SCRL);
  161. tap_code(KC_SCRL);
  162. tap_code(KC_3);
  163. }
  164. break;
  165. case MACRO_KVM_4:
  166. if (record->event.pressed) {
  167. tap_code(KC_SCRL);
  168. tap_code(KC_SCRL);
  169. tap_code(KC_4);
  170. }
  171. break;
  172. case MACRO_KVM_TG:
  173. if (record->event.pressed) {
  174. register_code(KC_LSFT);
  175. tap_code(KC_NUM);
  176. tap_code(KC_NUM);
  177. unregister_code(KC_LSFT);
  178. tap_code(KC_LCTL);
  179. }
  180. break;
  181. }
  182. return true;
  183. };
  184. /* vim: set ts=2 sw=2 et: */