keymap.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include QMK_KEYBOARD_H
  2. /*
  3. Security Note: While it is possible to use macros to send passwords, credit card numbers,
  4. and other sensitive information it is a supremely bad idea to do so. Anyone who gets a hold
  5. of your keyboard will be able to access that information by opening a text editor.
  6. */
  7. enum custom_keycodes
  8. {
  9. PASS_A = SAFE_RANGE,
  10. PASS_B
  11. };
  12. #define ___ KC_NO
  13. #define LAYOUT_melka( \
  14. K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \
  15. K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
  16. K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, \
  17. K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, \
  18. K40, K41, K42, K43, K44, K45, K46, K47, K48) \
  19. { \
  20. {K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D}, \
  21. {K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, ___}, \
  22. {K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K1D}, \
  23. {K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3E, K3D}, \
  24. {K40, K41, K42, ___, ___, K43, ___, K3C, K46, K0E, K44, K45, K47, K48} \
  25. }
  26. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  27. // 0: Base Layer
  28. LAYOUT_melka(
  29. KC_NUBS, 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_DEL, KC_BSPC,
  30. 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_ENT,
  31. 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_BSLS,
  32. MT(KC_LSFT, KC_5), KC_GRV, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, MT(KC_RSFT, KC_MINS), KC_UP, MO(1),
  33. KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_RGUI, KC_RALT, KC_LEFT, KC_DOWN, KC_RIGHT),
  34. // 1: Function Layer
  35. LAYOUT_melka(
  36. 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, _______, _______,
  37. _______, KC_WH_U, KC_UP, KC_WH_D, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  38. _______, KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, _______,
  39. TO(2), TO(3), _______, KC_APP, BL_STEP, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_VOLU, _______,
  40. _______, _______, _______, _______, _______, _______, _______, KC_VOLD, KC_MUTE),
  41. // 2: RGB Layer
  42. LAYOUT_melka(
  43. RGB_TOG, RGB_M_P, RGB_RMOD, RGB_MOD, RGB_M_B, RGB_M_R, RGB_M_SW, RGB_M_SN, RGB_M_K, RGB_M_X, RGB_M_G, RGB_M_T, _______, _______, RESET,
  44. _______, RGB_HUD, RGB_HUI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  45. _______, RGB_SAD, RGB_SAI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  46. TO(0), _______, RGB_VAD, RGB_VAI, _______, _______, _______, _______, _______, _______, _______, PASS_A, PASS_B, _______, _______,
  47. _______, _______, _______, _______, _______, _______, _______, _______, _______),
  48. // 3: Keypad Layer
  49. LAYOUT_melka(
  50. KC_ESC, _______, _______, _______, _______, _______, _______, _______, _______, KC_NLCK, KC_PEQL, KC_PSLS, KC_PAST, _______, _______,
  51. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P7, KC_P8, KC_P9, KC_PMNS, _______,
  52. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P4, KC_P5, KC_P6, KC_PPLS,
  53. TO(0), _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P1, KC_P2, KC_P3, KC_PENT, TO(0),
  54. _______, _______, _______, _______, KC_P0, KC_P0, KC_PDOT, KC_PENT, _______)
  55. };
  56. // Light LEDs 6 to 9 and 12 to 15 red when caps lock is active. Hard to ignore!
  57. const rgblight_segment_t PROGMEM rgb_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  58. {2, 4, HSV_RED}, // Light 4 LEDs, starting with LED 6
  59. {6, 4, HSV_RED} // Light 4 LEDs, starting with LED 12
  60. );
  61. // Light LEDs 9 & 10 in cyan when keyboard layer 1 is active
  62. const rgblight_segment_t PROGMEM rgb_function_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  63. {9, 2, HSV_CYAN}
  64. );
  65. // Light LEDs 11 & 12 in purple when keyboard layer 2 is active
  66. const rgblight_segment_t PROGMEM rgb_backlight_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  67. {10, 2, HSV_PURPLE}
  68. );
  69. const rgblight_segment_t PROGMEM rgb_keypad_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  70. {4, 4, HSV_RED}
  71. );
  72. // Now define the array of layers. Later layers take precedence
  73. const rgblight_segment_t* const PROGMEM rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  74. rgb_capslock_layer,
  75. rgb_function_layer,
  76. rgb_backlight_layer, // Overrides caps lock layer
  77. rgb_keypad_layer // Overrides other layers
  78. );
  79. layer_state_t layer_state_set_user(layer_state_t state) {
  80. // Both layers will light up if both kb layers are active
  81. rgblight_set_layer_state(1, layer_state_cmp(state, 1));
  82. rgblight_set_layer_state(2, layer_state_cmp(state, 2));
  83. return state;
  84. }
  85. bool led_update_user(led_t led_state) {
  86. rgblight_set_layer_state(0, led_state.caps_lock);
  87. return true;
  88. }
  89. void keyboard_post_init_user(void) {
  90. // Enable the LED layers
  91. rgblight_layers = rgb_layers;
  92. }
  93. // Loop
  94. void matrix_scan_user(void) {
  95. // Empty
  96. };
  97. static bool control_disabled = false;
  98. static bool delete_pressed = false;
  99. bool process_record_user(uint16_t keycode, keyrecord_t *record)
  100. {
  101. if (keycode == KC_BSPC)
  102. {
  103. if (record->event.pressed)
  104. {
  105. if (keyboard_report->mods & MOD_BIT(KC_LCTL))
  106. {
  107. delete_pressed = true;
  108. control_disabled = true;
  109. unregister_code(KC_LCTL);
  110. register_code(KC_DEL);
  111. return false;
  112. }
  113. }
  114. else if (delete_pressed)
  115. {
  116. delete_pressed = false;
  117. unregister_code(KC_DEL);
  118. if (control_disabled)
  119. {
  120. control_disabled = false;
  121. register_code(KC_LCTL);
  122. }
  123. return false;
  124. }
  125. }
  126. else if (keycode == KC_LCTL && !record->event.pressed && delete_pressed)
  127. {
  128. delete_pressed = false;
  129. control_disabled = false;
  130. unregister_code(KC_DEL);
  131. register_code(KC_BSPC);
  132. return false;
  133. }
  134. switch (keycode)
  135. {
  136. case PASS_A:
  137. if (record->event.pressed)
  138. {
  139. SEND_STRING(PASSWORD_A "\n");
  140. }
  141. break;
  142. case PASS_B:
  143. if (record->event.pressed)
  144. {
  145. SEND_STRING(PASSWORD_B "\n");
  146. }
  147. break;
  148. }
  149. return true;
  150. }