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 // Fillers to make layering more clear
37 #define _______ KC_TRNS
40 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
42 [_MALT] = LAYOUT( /* Malt Layout, customised for reduced columns (ex: quote and shift locations) */
43 KC_Q, KC_P, KC_Y, KC_C, KC_B, KC_V, KC_M, KC_U, KC_Z, KC_L,
44 KC_A, KC_N, KC_I, KC_S, KC_F, KC_D, KC_T, KC_H, KC_O, KC_R,
45 KC_COMM, KC_DOT, KC_J, KC_G, KC_SLSH, KC_SCLN, KC_W, KC_K, KC_QUOT, KC_X,
46 M(VOLU), M(ESCM), KC_TAB, KC_LCTL, KC_LALT, KC_ENT, KC_DEL, KC_PGUP,
47 M(VOLD), KC_LGUI, KC_E, FNKEY, SHIFT, KC_SPC, KC_BSPC, KC_PGDN
51 [_SHIFTED] = LAYOUT( /* Shifted Layer, layered so that tri_layer can be used, or selectively
52 able to modify individual key's shifted behaviour */
53 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
54 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
55 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
56 _______, _______, _______, _______, _______, _______, _______, _______,
57 _______, _______, _______, _______, _______, _______, _______, _______
62 [_FUNCTION] = LAYOUT( /* Function Layer, primary alternative layer featuring numpad on right hand,
63 cursor keys on left hand, and all symbols*/
64 KC_AMPR, KC_PERC, KC_UP, KC_CIRC, KC_PIPE, KC_LBRC, KC_7, KC_8, KC_9, KC_MINS,
65 KC_AT, KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH, KC_LPRN, KC_4, KC_5, KC_6, KC_PLUS,
66 KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR, KC_BSLS, KC_LCBR, KC_1, KC_2, KC_3, KC_ENT,
67 KC_HOME, KC_GRV, KC_PWR, _______, _______, KC_EQL, KC_TILD, KC_DOT,
68 KC_END, _______, _______, _______, _______, KC_0, _______, KC_PSCR
72 [_FUNCSHIFT] = LAYOUT( /* Function Shifted Layer, secondary alternative layer with closing brackets,
73 and F-keys under their numpad equivalents*/
74 _______, _______, _______, _______, _______, KC_RBRC, KC_F7, KC_F8, KC_F9, KC_F10,
75 _______, _______, _______, _______, _______, KC_RPRN, KC_F4, KC_F5, KC_F6, KC_F11,
76 _______, _______, _______, _______, _______, KC_RCBR, KC_F1, KC_F2, KC_F3, KC_F12,
77 _______, _______, _______, _______, _______, _______, _______, _______,
78 _______, _______, _______, _______, _______, _______, _______, _______
84 const uint16_t PROGMEM fn_actions[] = {
88 static uint16_t key_timer;
90 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
92 // MACRODOWN only works in this function
95 //switch multiplexing for media, short tap for volume up, long press for play/pause
97 if (record->event.pressed) {
98 key_timer = timer_read(); // if the key is being pressed, we start the timer.
99 } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
100 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
101 return MACRO(T(MPLY), END);
103 return MACRO(T(VOLU), END);
108 //switch multiplexing for media, short tap for volume down, long press for next track
110 if (record->event.pressed) {
111 key_timer = timer_read();
113 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
114 return MACRO(T(MNXT), END);
116 return MACRO(T(VOLD), END);
121 //switch multiplexing for escape, short tap for escape, long press for context menu
123 if (record->event.pressed) {
124 key_timer = timer_read();
126 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
127 return MACRO(T(APP), END);
129 return MACRO(T(ESC), END);
139 static bool singular_key = false;
141 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
144 layer = biton32(layer_state); // get the current layer
146 //custom layer handling for tri_layer,
149 if (record->event.pressed) {
150 key_timer = timer_read();
154 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
155 layer_off(_FUNCTION);
158 update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
161 //SHIFT is handled as LSHIFT in the general case
163 if (record->event.pressed) {
164 key_timer = timer_read();
167 register_code(KC_LSFT);
169 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
171 unregister_code(KC_LSFT);
174 update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
178 //If any other key was pressed during the layer mod hold period,
179 //then the layer mod was used momentarily, and should block latching
181 singular_key = false;
185 //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
186 if (layer == _FUNCSHIFT) {
187 //F1-F12 should be sent as unshifted keycodes,
188 //and ] needs to be unshifted or it is sent as }
189 if ( (keycode >= KC_F1 && keycode <= KC_F12)
190 || keycode == KC_RBRC ) {
191 if (record->event.pressed) {
192 unregister_mods(MOD_LSFT);
194 register_mods(MOD_LSFT);
202 void matrix_scan_user(void) {
203 uint8_t layer = biton32(layer_state);