logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (6865B)


  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. enum mitosis_layers
  9. {
  10. _MALT,
  11. _SHIFTED,
  12. _FUNCTION,
  13. _FUNCSHIFT
  14. };
  15. enum mitosis_keycodes
  16. {
  17. FNKEY = SAFE_RANGE,
  18. SHIFT,
  19. M_VOLU,
  20. M_VOLD,
  21. M_ESCM
  22. };
  23. #define LONGPRESS_DELAY 150
  24. #define LAYER_TOGGLE_DELAY 300
  25. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. [_MALT] = LAYOUT( /* Malt Layout, customised for reduced columns (ex: quote and shift locations) */
  27. KC_Q, KC_P, KC_Y, KC_C, KC_B, KC_V, KC_M, KC_U, KC_Z, KC_L,
  28. KC_A, KC_N, KC_I, KC_S, KC_F, KC_D, KC_T, KC_H, KC_O, KC_R,
  29. KC_COMM, KC_DOT, KC_J, KC_G, KC_SLSH, KC_SCLN, KC_W, KC_K, KC_QUOT, KC_X,
  30. M_VOLU, M_ESCM, KC_TAB, KC_LCTL, KC_LALT, KC_ENT, KC_DEL, KC_PGUP,
  31. M_VOLD, KC_LGUI, KC_E, FNKEY, SHIFT, KC_SPC, KC_BSPC, KC_PGDN
  32. ),
  33. [_SHIFTED] = LAYOUT( /* Shifted Layer, layered so that tri_layer can be used, or selectively
  34. able to modify individual key's shifted behaviour */
  35. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  36. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  37. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  38. _______, _______, _______, _______, _______, _______, _______, _______,
  39. _______, _______, _______, _______, _______, _______, _______, _______
  40. ),
  41. [_FUNCTION] = LAYOUT( /* Function Layer, primary alternative layer featuring numpad on right hand,
  42. cursor keys on left hand, and all symbols*/
  43. KC_AMPR, KC_PERC, KC_UP, KC_CIRC, KC_PIPE, KC_LBRC, KC_7, KC_8, KC_9, KC_MINS,
  44. KC_AT, KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH, KC_LPRN, KC_4, KC_5, KC_6, KC_PLUS,
  45. KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR, KC_BSLS, KC_LCBR, KC_1, KC_2, KC_3, KC_ENT,
  46. KC_HOME, KC_GRV, KC_PWR, _______, _______, KC_EQL, KC_TILD, KC_DOT,
  47. KC_END, _______, _______, _______, _______, KC_0, _______, KC_PSCR
  48. ),
  49. [_FUNCSHIFT] = LAYOUT( /* Function Shifted Layer, secondary alternative layer with closing brackets,
  50. and F-keys under their numpad equivalents*/
  51. _______, _______, _______, _______, _______, KC_RBRC, KC_F7, KC_F8, KC_F9, KC_F10,
  52. _______, _______, _______, _______, _______, KC_RPRN, KC_F4, KC_F5, KC_F6, KC_F11,
  53. _______, _______, _______, _______, _______, KC_RCBR, KC_F1, KC_F2, KC_F3, KC_F12,
  54. _______, _______, _______, _______, _______, _______, _______, _______,
  55. _______, _______, _______, _______, _______, _______, _______, _______
  56. )
  57. };
  58. static uint16_t key_timer;
  59. static bool singular_key = false;
  60. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  61. uint8_t layer;
  62. layer = get_highest_layer(layer_state); // get the current layer
  63. //custom layer handling for tri_layer,
  64. switch (keycode) {
  65. case FNKEY:
  66. if (record->event.pressed) {
  67. key_timer = timer_read();
  68. singular_key = true;
  69. layer_on(_FUNCTION);
  70. } else {
  71. if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
  72. layer_off(_FUNCTION);
  73. }
  74. }
  75. update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
  76. return false;
  77. break;
  78. //SHIFT is handled as LSHIFT in the general case
  79. case SHIFT:
  80. if (record->event.pressed) {
  81. key_timer = timer_read();
  82. singular_key = true;
  83. layer_on(_SHIFTED);
  84. register_code(KC_LSFT);
  85. } else {
  86. if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
  87. layer_off(_SHIFTED);
  88. unregister_code(KC_LSFT);
  89. }
  90. }
  91. update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
  92. return false;
  93. break;
  94. //switch multiplexing for media, short tap for volume up, long press for play/pause
  95. case M_VOLU:
  96. if (record->event.pressed) {
  97. key_timer = timer_read(); // if the key is being pressed, we start the timer.
  98. } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
  99. if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
  100. tap_code(KC_MPLY);
  101. } else {
  102. tap_code(KC_VOLU);
  103. }
  104. }
  105. return false;
  106. //switch multiplexing for media, short tap for volume down, long press for next track
  107. case M_VOLD:
  108. if (record->event.pressed) {
  109. key_timer = timer_read();
  110. } else {
  111. if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
  112. tap_code(KC_MNXT);
  113. } else {
  114. tap_code(KC_VOLD);
  115. }
  116. }
  117. return false;
  118. //switch multiplexing for escape, short tap for escape, long press for context menu
  119. case M_ESCM:
  120. if (record->event.pressed) {
  121. key_timer = timer_read();
  122. } else {
  123. if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
  124. tap_code(KC_APP);
  125. } else {
  126. tap_code(KC_ESC);
  127. }
  128. }
  129. return false;
  130. //If any other key was pressed during the layer mod hold period,
  131. //then the layer mod was used momentarily, and should block latching
  132. default:
  133. singular_key = false;
  134. break;
  135. }
  136. //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
  137. if (layer == _FUNCSHIFT) {
  138. //F1-F12 should be sent as unshifted keycodes,
  139. //and ] needs to be unshifted or it is sent as }
  140. if ( (keycode >= KC_F1 && keycode <= KC_F12)
  141. || keycode == KC_RBRC ) {
  142. if (record->event.pressed) {
  143. unregister_mods(MOD_LSFT);
  144. } else {
  145. register_mods(MOD_LSFT);
  146. }
  147. }
  148. }
  149. return true;
  150. };
  151. void matrix_scan_user(void) {
  152. uint8_t layer = get_highest_layer(layer_state);
  153. switch (layer) {
  154. case _MALT:
  155. set_led_off;
  156. break;
  157. case _FUNCTION:
  158. set_led_blue;
  159. break;
  160. case _SHIFTED:
  161. set_led_red;
  162. break;
  163. case _FUNCSHIFT:
  164. set_led_green;
  165. break;
  166. default:
  167. break;
  168. }
  169. };