2
0

keymap.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // this is the style you want to emulate.
  2. // This is the canonical layout file for the Quantum project. If you want to add another keyboard,
  3. #include QMK_KEYBOARD_H
  4. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  5. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  6. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  7. // entirely and just use numbers.
  8. #define _QWERTY 0
  9. #define _LOWER 1
  10. #define _RAISE 2
  11. #define _MOUSE 8
  12. #define _ADJUST 16
  13. enum dichotomy_keycodes
  14. {
  15. QWERTY = SAFE_RANGE,
  16. LOWER,
  17. RAISE,
  18. ADJUST,
  19. MOUKEY,
  20. MS_BTN1,
  21. MS_BTN2,
  22. MS_BTN3
  23. };
  24. #define RED_BRIGHTNESS 3
  25. #define GREEN_BRIGHTNESS 2
  26. #define BLUE_BRIGHTNESS 2
  27. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  28. [_QWERTY] = LAYOUT( /* Base layout, nearly qwerty but with modifications because it's not a full keyboard. Obviously. */
  29. KC_ESCAPE, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  30. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT,
  31. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, MOUKEY,
  32. KC_LCTL, KC_LALT, MOUKEY, KC_RGUI, KC_RALT, KC_RCTL,
  33. MS_BTN3, SFT_T(KC_ESCAPE), KC_LGUI, KC_BSPC, KC_SPC, RAISE, LOWER, MS_BTN3
  34. ),
  35. [_RAISE] = LAYOUT( /* Shifted layout, small changes (because angle brackets have been moved to thumb cluster buttons) */
  36. _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
  37. _______, _______, KC_VOLD, KC_VOLU, KC_MPLY, KC_MFFD, KC_MUTE, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, _______,
  38. _______, _______, KC_GRV, _______, _______, KC_MRWD, _______, _______, _______, KC_BSLS, KC_QUOT, _______,
  39. _______, _______, _______, _______, _______, _______,
  40. _______, _______, KC_LABK, _______, _______, KC_RABK, _______, _______
  41. ),
  42. [_LOWER] = LAYOUT( /* Number layout, basically the main function layer */
  43. _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
  44. _______, _______, KC_VOLD, KC_VOLU, KC_MPLY, KC_MFFD, KC_MUTE, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, _______,
  45. _______, _______, KC_TILD, _______, _______, KC_MRWD, _______, _______, _______, KC_PIPE, KC_DQT, _______,
  46. _______, _______, _______, _______, _______, _______,
  47. _______, RAISE, _______, _______, _______, _______, _______, _______
  48. ),
  49. [_ADJUST] = LAYOUT( /* Shifted number/function layout, for per-key control. Only active when shift is held, and number is toggled or held */
  50. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_UP, _______, _______, _______,
  51. KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______,
  52. KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, _______, _______, _______, _______, _______, _______,
  53. _______, _______, _______, _______, _______, _______,
  54. _______, _______, _______, _______, _______, _______, _______, _______
  55. ),
  56. [_MOUSE] = LAYOUT( /* Mouse layer, including buttons for clicking. */
  57. _______, _______, _______, _______, _______, _______, KC_VOLU, KC_HOME, KC_PGUP, _______, _______, _______,
  58. _______, _______, _______, _______, _______, _______, _______, MS_BTN1, MS_BTN2, _______, _______, _______,
  59. _______, _______, _______, _______, _______, _______, KC_VOLD, KC_END, KC_PGDN, _______, _______, _______,
  60. _______, _______, _______, _______, KC_UP, _______,
  61. _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______
  62. )
  63. }; // end keymaps block
  64. static bool shift_held = false;
  65. static bool shift_suspended = false;
  66. report_mouse_t currentReport = {};
  67. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  68. switch (keycode) {
  69. case QWERTY:
  70. if (record->event.pressed) {
  71. set_single_persistent_default_layer(_QWERTY);
  72. }
  73. return false;
  74. break;
  75. case LOWER:
  76. if (record->event.pressed) {
  77. layer_on(_LOWER);
  78. grn_led_on();
  79. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  80. } else {
  81. layer_off(_LOWER);
  82. grn_led_off();
  83. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  84. }
  85. return false;
  86. break;
  87. //SHIFT is handled as LSHIFT in the general case - 'toggle' shoudl activate caps, while the layer is only active when shift is held.
  88. case RAISE:
  89. if (record->event.pressed) {
  90. layer_on(_RAISE);
  91. red_led_on();
  92. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  93. } else {
  94. layer_off(_RAISE);
  95. red_led_off();
  96. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  97. }
  98. return false;
  99. break;
  100. case ADJUST:
  101. if (record->event.pressed) {
  102. layer_on(_ADJUST);
  103. } else {
  104. layer_off(_ADJUST);
  105. }
  106. return false;
  107. break;
  108. //MOUSE layer needs to be handled the same way as NUMKEY, but differently from shift
  109. case MOUKEY:
  110. if (record->event.pressed) {
  111. layer_on(_MOUSE);
  112. blu_led_on();
  113. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  114. } else {
  115. layer_off(_MOUSE);
  116. blu_led_off();
  117. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  118. }
  119. return false;
  120. break;
  121. //mouse buttons, for 1-3, to update the mouse report:
  122. case MS_BTN1:
  123. currentReport = pointing_device_get_report();
  124. if (record->event.pressed) {
  125. if (shift_held && shift_suspended){
  126. register_code(KC_LSFT);
  127. shift_suspended = false;
  128. }
  129. //update mouse report here
  130. currentReport.buttons |= MOUSE_BTN1; //MOUSE_BTN1 is a const defined in report.h
  131. } else {
  132. //update mouse report here
  133. currentReport.buttons &= ~MOUSE_BTN1;
  134. }
  135. pointing_device_set_report(currentReport);
  136. return false;
  137. break;
  138. case MS_BTN2:
  139. currentReport = pointing_device_get_report();
  140. if (record->event.pressed) {
  141. if (shift_held && shift_suspended){
  142. register_code(KC_LSFT);
  143. shift_suspended = false;
  144. }
  145. //update mouse report here
  146. currentReport.buttons |= MOUSE_BTN2; //MOUSE_BTN2 is a const defined in report.h
  147. } else {
  148. //update mouse report here
  149. currentReport.buttons &= ~MOUSE_BTN2;
  150. }
  151. pointing_device_set_report(currentReport);
  152. return false;
  153. break;
  154. case MS_BTN3:
  155. currentReport = pointing_device_get_report();
  156. if (record->event.pressed) {
  157. if (shift_held && shift_suspended){
  158. register_code(KC_LSFT);
  159. shift_suspended = false;
  160. }
  161. //update mouse report here
  162. currentReport.buttons |= MOUSE_BTN3; //MOUSE_BTN3 is a const defined in report.h
  163. } else {
  164. //update mouse report here
  165. currentReport.buttons &= ~MOUSE_BTN3;
  166. }
  167. pointing_device_set_report(currentReport);
  168. return false;
  169. break;
  170. //Additionally, if NS_ keys are in use, then shift may be held (but is
  171. //disabled for the unshifted keycodes to be send. Check the bool and
  172. //register shift as necessary.
  173. // default:
  174. // if (shift_held){
  175. // register_code(KC_LSFT);
  176. // }
  177. // break;
  178. }
  179. return true;
  180. };