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,
4 #include QMK_KEYBOARD_H
6 // Each layer gets a name for readability, which is then used in the keymap matrix below.
7 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
8 // Layer names don't all need to be of the same length, obviously, and you can also skip them
9 // entirely and just use numbers.
25 // Macro definitions for readability
33 #define LONGPRESS_DELAY 150
34 #define LAYER_TOGGLE_DELAY 300
36 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
38 [_MALT] = LAYOUT( /* Malt Layout, customised for reduced columns (ex: quote and shift locations) */
39 KC_Q, KC_P, KC_Y, KC_C, KC_B, KC_V, KC_M, KC_U, KC_Z, KC_L,
40 KC_A, KC_N, KC_I, KC_S, KC_F, KC_D, KC_T, KC_H, KC_O, KC_R,
41 KC_COMM, KC_DOT, KC_J, KC_G, KC_SLSH, KC_SCLN, KC_W, KC_K, KC_QUOT, KC_X,
42 M(VOLU), M(ESCM), KC_TAB, KC_LCTL, KC_LALT, KC_ENT, KC_DEL, KC_PGUP,
43 M(VOLD), KC_LGUI, KC_E, FNKEY, SHIFT, KC_SPC, KC_BSPC, KC_PGDN
47 [_SHIFTED] = LAYOUT( /* Shifted Layer, layered so that tri_layer can be used, or selectively
48 able to modify individual key's shifted behaviour */
49 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
50 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
51 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
52 _______, _______, _______, _______, _______, _______, _______, _______,
53 _______, _______, _______, _______, _______, _______, _______, _______
58 [_FUNCTION] = LAYOUT( /* Function Layer, primary alternative layer featuring numpad on right hand,
59 cursor keys on left hand, and all symbols*/
60 KC_AMPR, KC_PERC, KC_UP, KC_CIRC, KC_PIPE, KC_LBRC, KC_7, KC_8, KC_9, KC_MINS,
61 KC_AT, KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH, KC_LPRN, KC_4, KC_5, KC_6, KC_PLUS,
62 KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR, KC_BSLS, KC_LCBR, KC_1, KC_2, KC_3, KC_ENT,
63 KC_HOME, KC_GRV, KC_PWR, _______, _______, KC_EQL, KC_TILD, KC_DOT,
64 KC_END, _______, _______, _______, _______, KC_0, _______, KC_PSCR
68 [_FUNCSHIFT] = LAYOUT( /* Function Shifted Layer, secondary alternative layer with closing brackets,
69 and F-keys under their numpad equivalents*/
70 _______, _______, _______, _______, _______, KC_RBRC, KC_F7, KC_F8, KC_F9, KC_F10,
71 _______, _______, _______, _______, _______, KC_RPRN, KC_F4, KC_F5, KC_F6, KC_F11,
72 _______, _______, _______, _______, _______, KC_RCBR, KC_F1, KC_F2, KC_F3, KC_F12,
73 _______, _______, _______, _______, _______, _______, _______, _______,
74 _______, _______, _______, _______, _______, _______, _______, _______
79 static uint16_t key_timer;
81 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
83 // MACRODOWN only works in this function
86 //switch multiplexing for media, short tap for volume up, long press for play/pause
88 if (record->event.pressed) {
89 key_timer = timer_read(); // if the key is being pressed, we start the timer.
90 } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
91 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
92 return MACRO(T(MPLY), END);
94 return MACRO(T(VOLU), END);
99 //switch multiplexing for media, short tap for volume down, long press for next track
101 if (record->event.pressed) {
102 key_timer = timer_read();
104 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
105 return MACRO(T(MNXT), END);
107 return MACRO(T(VOLD), END);
112 //switch multiplexing for escape, short tap for escape, long press for context menu
114 if (record->event.pressed) {
115 key_timer = timer_read();
117 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
118 return MACRO(T(APP), END);
120 return MACRO(T(ESC), END);
130 static bool singular_key = false;
132 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
135 layer = biton32(layer_state); // get the current layer
137 //custom layer handling for tri_layer,
140 if (record->event.pressed) {
141 key_timer = timer_read();
145 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
146 layer_off(_FUNCTION);
149 update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
152 //SHIFT is handled as LSHIFT in the general case
154 if (record->event.pressed) {
155 key_timer = timer_read();
158 register_code(KC_LSFT);
160 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
162 unregister_code(KC_LSFT);
165 update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
169 //If any other key was pressed during the layer mod hold period,
170 //then the layer mod was used momentarily, and should block latching
172 singular_key = false;
176 //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
177 if (layer == _FUNCSHIFT) {
178 //F1-F12 should be sent as unshifted keycodes,
179 //and ] needs to be unshifted or it is sent as }
180 if ( (keycode >= KC_F1 && keycode <= KC_F12)
181 || keycode == KC_RBRC ) {
182 if (record->event.pressed) {
183 unregister_mods(MOD_LSFT);
185 register_mods(MOD_LSFT);
193 void matrix_scan_user(void) {
194 uint8_t layer = biton32(layer_state);