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,
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.
10 enum dichotomy_layers {
18 #define LONGPRESS_COUNT 4
20 enum dichotomy_keycodes
25 CK_TE, //these 4 CK_XXXX keys are special "alternate long-press" keys controlled with unique timers. Make sure you understand them before you mess with them.
36 #define CUSTOM_LONGPRESS 150
37 #define CUSTOM_TOGGLE_TIME 300
39 #define RED_BRIGHTNESS 3
40 #define GREEN_BRIGHTNESS 2
41 #define BLUE_BRIGHTNESS 2
43 // Fillers to make layering more clear
44 #define _______ KC_TRNS
47 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
48 [_BS] = LAYOUT( /* Base layout, nearly qwerty but with modifications because it's not a full keyboard. Obviously. */
49 CK_TE, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
50 NUMKEY, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, CK_QE,
51 SFTKEY, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, MOUKEY,
52 KC_LCTL, KC_LALT, KC_LGUI, KC_RGUI, KC_RALT, KC_RCTL,
53 MS_BTN3, KC_LBRC, KC_LPRN, KC_SPC, KC_SPC, KC_RPRN, KC_RBRC, MS_BTN3
56 [_SF] = LAYOUT( /* Shifted layout, small changes (because angle brackets have been moved to thumb cluster buttons) */
57 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
58 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
59 _______, _______, _______, _______, _______, _______, _______, _______, NS_HYPH, KC_UNDS, _______, _______,
60 _______, _______, _______, _______, _______, _______,
61 _______, _______, KC_LABK, _______, _______, KC_RABK, _______, _______
64 [_NM] = LAYOUT( /* Number layout, basically the main function layer */
65 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, _______,
66 _______, CK_1G, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, CK_BSPE,
67 _______, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, _______,
68 _______, _______, _______, _______, _______, _______,
69 _______, _______, _______, _______, _______, _______, _______, _______
72 [_NS] = LAYOUT( /* Shifted number/function layout, for per-key control. Only active when shift is held, and number is toggled or held */
73 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
74 _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PLUS, NS_EQU, _______,
75 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
76 _______, _______, _______, _______, _______, _______,
77 _______, _______, _______, _______, _______, _______, _______, _______
80 [_MS] = LAYOUT( /* Mouse layer, including buttons for clicking. */
81 _______, _______, _______, _______, _______, _______, KC_VOLU, KC_HOME, KC_PGUP, _______, _______, _______,
82 _______, _______, _______, _______, _______, _______, _______, MS_BTN1, MS_BTN2, _______, _______, _______,
83 _______, _______, _______, _______, _______, _______, KC_VOLD, KC_END, KC_PGDN, _______, _______, _______,
84 _______, _______, _______, _______, KC_UP, _______,
85 _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______
91 const uint16_t PROGMEM fn_actions[] = {
95 static uint16_t special_timers[LONGPRESS_COUNT] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF};
96 static bool special_key_states[LONGPRESS_COUNT] = {0,0,0,0};
97 static bool special_key_pressed[LONGPRESS_COUNT] = {0,0,0,0};
99 static uint16_t shift_timer;
100 static uint16_t num_timer;
101 static uint16_t mouse_timer;
103 static uint8_t red_timer;
104 static uint8_t green_timer;
105 static uint8_t blue_timer;
107 static bool shift_singular_key = false;
108 static bool number_singular_key = false;
109 static bool mouse_singular_key = false;
110 static bool capsLED = false;
111 static bool shiftLED = false;
112 static bool numLED = false;
113 static bool mouseLED = false;
115 static bool shift_held = false;
116 static bool shift_suspended = false;
117 report_mouse_t currentReport = {};
119 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
121 //layer = biton32(layer_state); // get the current layer //Or don't, I didn't use it.
122 bool returnVal = true; //this is to determine if more key processing is needed.
124 //custom layer handling for tri_layer,
127 if (record->event.pressed) {
128 num_timer = timer_read();
129 number_singular_key = true;
133 if (timer_elapsed(num_timer) < CUSTOM_TOGGLE_TIME && number_singular_key) {
134 //do nothing, the layer has already been inverted
140 update_tri_layer(_NM, _SF, _NS);
143 //SHIFT is handled as LSHIFT in the general case - 'toggle' shoudl activate caps, while the layer is only active when shift is held.
145 if (record->event.pressed) {
148 shift_suspended = false;
149 shift_timer = timer_read();
150 shift_singular_key = true;
152 register_code(KC_LSFT);
156 if (timer_elapsed(shift_timer) < CUSTOM_TOGGLE_TIME && shift_singular_key) {
157 //this was basically a toggle, so activate/deactivate caps lock.
158 SEND_STRING(SS_TAP(X_CAPSLOCK));
162 unregister_code(KC_LSFT);
164 update_tri_layer(_NM, _SF, _NS);
167 //MOUSE layer needs to be handled the same way as NUMKEY, but differently from shift
169 if (record->event.pressed) {
170 mouse_timer = timer_read();
171 mouse_singular_key = true;
173 mouseLED = !mouseLED;
175 if (timer_elapsed(mouse_timer) < CUSTOM_TOGGLE_TIME && mouse_singular_key){
176 //do nothing, it was a toggle (and it's already been toggled)
179 mouseLED = !mouseLED;
184 //Custom macros for strange keys with different long-tap behavior
186 if (shift_held && shift_suspended){
187 register_code(KC_LSFT);
188 shift_suspended = false;
190 if (record->event.pressed) {
191 special_timers[CK_1G-SAFE_RANGE] = timer_read();
192 special_key_pressed[CK_1G-SAFE_RANGE] = 1;
194 if (special_key_states[CK_1G-SAFE_RANGE]){
195 //key was activated after custom_longpress, need to close those keycodes
196 special_key_states[CK_1G-SAFE_RANGE] = 0;
197 unregister_code(KC_GRAVE);
199 if (special_key_pressed[CK_1G-SAFE_RANGE]){
200 //key was not activated, return macro activating proper, pre-long-tap key
201 SEND_STRING(SS_TAP(X_1));
202 special_key_pressed[CK_1G-SAFE_RANGE] = 0;
204 //the short key was already sent, because another key was pressed.
213 if (shift_held && shift_suspended){
214 register_code(KC_LSFT);
215 shift_suspended = false;
217 if (record->event.pressed) {
218 special_timers[CK_BSPE-SAFE_RANGE] = timer_read();
219 special_key_pressed[CK_BSPE-SAFE_RANGE] = 1;
221 if (special_key_states[CK_BSPE-SAFE_RANGE]){
222 //key was activated after custom_longpress, need to close those keycodes
223 special_key_states[CK_BSPE-SAFE_RANGE] = 0;
224 unregister_code(KC_ENTER);
226 if (special_key_pressed[CK_BSPE-SAFE_RANGE]){
227 //key was not activated, return macro activating proper, pre-long-tap key
228 SEND_STRING(SS_TAP(X_BSLASH));
229 special_key_pressed[CK_BSPE-SAFE_RANGE] = 0;
231 //the short key was already sent, because another key was pressed.
239 if (shift_held && shift_suspended){
240 register_code(KC_LSFT);
241 shift_suspended = false;
243 if (record->event.pressed) {
244 special_timers[CK_QE-SAFE_RANGE] = timer_read();
245 special_key_pressed[CK_QE-SAFE_RANGE] = 1;
247 if (special_key_states[CK_QE-SAFE_RANGE]){
248 //key was activated after custom_longpress, need to close those keycodes
249 special_key_states[CK_QE-SAFE_RANGE] = 0;
250 unregister_code(KC_ENTER);
252 if (special_key_pressed[CK_QE-SAFE_RANGE]){
253 //the long-press key was not activated, return macro activating proper, pre-long-tap key
254 SEND_STRING(SS_TAP(X_QUOTE));
255 special_key_pressed[CK_QE-SAFE_RANGE] = 0;
257 //the short key was already sent, because another key was pressed.
265 if (shift_held && shift_suspended){
266 register_code(KC_LSFT);
267 shift_suspended = false;
269 if (record->event.pressed) {
270 special_timers[CK_TE-SAFE_RANGE] = timer_read();
271 special_key_pressed[CK_TE-SAFE_RANGE] = 1;
273 if (special_key_states[CK_TE-SAFE_RANGE]){
274 //key was activated after custom_longpress, need to close those keycodes
275 special_key_states[CK_TE-SAFE_RANGE] = 0;
276 unregister_code(KC_ESCAPE);
278 if (special_key_pressed[CK_TE-SAFE_RANGE]){
279 //the long-press key was not activated, return macro activating proper, pre-long-tap key
280 SEND_STRING(SS_TAP(X_TAB));
281 special_key_pressed[CK_TE-SAFE_RANGE] = 0;
283 //the short key was already sent, because another key was pressed.
290 //No-shift keys, they unregister the KC_LSFT code so they can send
291 //unshifted values - but they don't change the bool. if any other
292 //key is pressed and the bool is set, KC_LSFT is registered again.
294 if (record->event.pressed) {
295 shift_suspended = true;
296 unregister_code(KC_LSFT);
297 register_code(KC_MINS);
299 unregister_code(KC_MINS);
300 if (shift_held && shift_suspended){
301 register_code(KC_LSFT);
302 shift_suspended = false;
308 if (record->event.pressed) {
309 shift_suspended = true;
310 unregister_code(KC_LSFT);
311 register_code(KC_EQUAL);
313 unregister_code(KC_EQUAL);
314 if (shift_held && shift_suspended){
315 register_code(KC_LSFT);
316 shift_suspended = false;
322 //mouse buttons, for 1-3, to update the mouse report:
324 currentReport = pointing_device_get_report();
325 if (record->event.pressed) {
326 if (shift_held && shift_suspended){
327 register_code(KC_LSFT);
328 shift_suspended = false;
330 //update mouse report here
331 currentReport.buttons |= MOUSE_BTN1; //MOUSE_BTN1 is a const defined in report.h
333 //update mouse report here
334 currentReport.buttons &= ~MOUSE_BTN1;
336 pointing_device_set_report(currentReport);
340 currentReport = pointing_device_get_report();
341 if (record->event.pressed) {
342 if (shift_held && shift_suspended){
343 register_code(KC_LSFT);
344 shift_suspended = false;
346 //update mouse report here
347 currentReport.buttons |= MOUSE_BTN2; //MOUSE_BTN2 is a const defined in report.h
349 //update mouse report here
350 currentReport.buttons &= ~MOUSE_BTN2;
352 pointing_device_set_report(currentReport);
356 currentReport = pointing_device_get_report();
357 if (record->event.pressed) {
358 if (shift_held && shift_suspended){
359 register_code(KC_LSFT);
360 shift_suspended = false;
362 //update mouse report here
363 currentReport.buttons |= MOUSE_BTN3; //MOUSE_BTN3 is a const defined in report.h
365 //update mouse report here
366 currentReport.buttons &= ~MOUSE_BTN3;
368 pointing_device_set_report(currentReport);
371 //Additionally, if NS_ keys are in use, then shift may be held (but is
372 //disabled for the unshifted keycodes to be send. Check the bool and
373 //register shift as necessary.
376 register_code(KC_LSFT);
386 //don't want to reset single key variables
389 //If any other key was pressed during the layer mod hold period,
390 //then the layer mod was used momentarily, and should block latching
391 shift_singular_key = false;
392 number_singular_key = false;
393 mouse_singular_key = false;
415 //Do nothing, don't want to trigger the timer key rollover
418 //Now we're checking to see if any of the special timer keys are pressed
419 //if so, we need to activate their short-press features
420 if (record->event.pressed) {
421 for (uint8_t i = 0; i<LONGPRESS_COUNT; i++){
422 if ((!special_key_states[i]) && special_key_pressed[i]){
423 switch (i + SAFE_RANGE){
425 SEND_STRING(SS_TAP(X_1));
428 SEND_STRING(SS_TAP(X_BSLASH));
431 SEND_STRING(SS_TAP(X_QUOTE));
434 SEND_STRING(SS_TAP(X_TAB));
437 special_key_pressed[i] = 0;
441 //do nothing, we don't want to trigger short presses on key releases.
448 void matrix_scan_user(void) {
449 //uint8_t layer = biton32(layer_state);
450 for (uint8_t i = 0; i<LONGPRESS_COUNT; i++){
451 if ((timer_elapsed(special_timers[i]) >= CUSTOM_LONGPRESS) && (!special_key_states[i]) && special_key_pressed[i]){
452 switch (i + SAFE_RANGE){
454 register_code(KC_GRAVE);
457 register_code(KC_ENTER);
460 register_code(KC_ENTER);
463 register_code(KC_ESCAPE);
466 special_key_pressed[i] = 0;
467 special_key_states[i] = 1;
470 if (shiftLED || capsLED){
472 if (red_timer < RED_BRIGHTNESS){
484 if (green_timer < GREEN_BRIGHTNESS){
496 if (blue_timer < BLUE_BRIGHTNESS){