Merge commit '8858438a770c1c982f33b296447ca77176c751f7'
[jackhill/qmk/firmware.git] / quantum / quantum_keycodes.h
1 /* Copyright 2016-2017 Jack Humbert
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 #ifndef QUANTUM_KEYCODES_H
17 #define QUANTUM_KEYCODES_H
18
19 #ifndef MIDI_ENABLE_STRICT
20 #define MIDI_ENABLE_STRICT 0
21 #endif
22
23 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED))
24 #ifndef MIDI_TONE_KEYCODE_OCTAVES
25 #define MIDI_TONE_KEYCODE_OCTAVES 3
26 #endif
27 #endif
28
29 enum quantum_keycodes {
30 // Ranges used in shortucuts - not to be used directly
31 QK_TMK = 0x0000,
32 QK_TMK_MAX = 0x00FF,
33 QK_MODS = 0x0100,
34 QK_LCTL = 0x0100,
35 QK_LSFT = 0x0200,
36 QK_LALT = 0x0400,
37 QK_LGUI = 0x0800,
38 QK_RMODS_MIN = 0x1000,
39 QK_RCTL = 0x1100,
40 QK_RSFT = 0x1200,
41 QK_RALT = 0x1400,
42 QK_RGUI = 0x1800,
43 QK_MODS_MAX = 0x1FFF,
44 QK_FUNCTION = 0x2000,
45 QK_FUNCTION_MAX = 0x2FFF,
46 QK_MACRO = 0x3000,
47 QK_MACRO_MAX = 0x3FFF,
48 QK_LAYER_TAP = 0x4000,
49 QK_LAYER_TAP_MAX = 0x4FFF,
50 QK_TO = 0x5000,
51 QK_TO_MAX = 0x50FF,
52 QK_MOMENTARY = 0x5100,
53 QK_MOMENTARY_MAX = 0x51FF,
54 QK_DEF_LAYER = 0x5200,
55 QK_DEF_LAYER_MAX = 0x52FF,
56 QK_TOGGLE_LAYER = 0x5300,
57 QK_TOGGLE_LAYER_MAX = 0x53FF,
58 QK_ONE_SHOT_LAYER = 0x5400,
59 QK_ONE_SHOT_LAYER_MAX = 0x54FF,
60 QK_ONE_SHOT_MOD = 0x5500,
61 QK_ONE_SHOT_MOD_MAX = 0x55FF,
62 #ifndef DISABLE_CHORDING
63 QK_CHORDING = 0x5600,
64 QK_CHORDING_MAX = 0x56FF,
65 #endif
66 QK_TAP_DANCE = 0x5700,
67 QK_TAP_DANCE_MAX = 0x57FF,
68 QK_LAYER_TAP_TOGGLE = 0x5800,
69 QK_LAYER_TAP_TOGGLE_MAX = 0x58FF,
70 QK_MOD_TAP = 0x6000,
71 QK_MOD_TAP_MAX = 0x7FFF,
72 #if defined(UNICODEMAP_ENABLE) && defined(UNICODE_ENABLE)
73 #error "Cannot enable both UNICODEMAP && UNICODE"
74 #endif
75 #ifdef UNICODE_ENABLE
76 QK_UNICODE = 0x8000,
77 QK_UNICODE_MAX = 0xFFFF,
78 #endif
79 #ifdef UNICODEMAP_ENABLE
80 QK_UNICODE_MAP = 0x8000,
81 QK_UNICODE_MAP_MAX = 0x83FF,
82 #endif
83
84 // Loose keycodes - to be used directly
85
86 RESET = 0x5C00,
87 DEBUG,
88 MAGIC_SWAP_CONTROL_CAPSLOCK,
89 MAGIC_CAPSLOCK_TO_CONTROL,
90 MAGIC_SWAP_LALT_LGUI,
91 MAGIC_SWAP_RALT_RGUI,
92 MAGIC_NO_GUI,
93 MAGIC_SWAP_GRAVE_ESC,
94 MAGIC_SWAP_BACKSLASH_BACKSPACE,
95 MAGIC_HOST_NKRO,
96 MAGIC_SWAP_ALT_GUI,
97 MAGIC_UNSWAP_CONTROL_CAPSLOCK,
98 MAGIC_UNCAPSLOCK_TO_CONTROL,
99 MAGIC_UNSWAP_LALT_LGUI,
100 MAGIC_UNSWAP_RALT_RGUI,
101 MAGIC_UNNO_GUI,
102 MAGIC_UNSWAP_GRAVE_ESC,
103 MAGIC_UNSWAP_BACKSLASH_BACKSPACE,
104 MAGIC_UNHOST_NKRO,
105 MAGIC_UNSWAP_ALT_GUI,
106 MAGIC_TOGGLE_NKRO,
107 GRAVE_ESC,
108
109 // Leader key
110 #ifndef DISABLE_LEADER
111 KC_LEAD,
112 #endif
113
114 // Audio on/off/toggle
115 AU_ON,
116 AU_OFF,
117 AU_TOG,
118
119 #ifdef FAUXCLICKY_ENABLE
120 // Faux clicky
121 FC_ON,
122 FC_OFF,
123 FC_TOG,
124 #endif
125
126 // Music mode on/off/toggle
127 MU_ON,
128 MU_OFF,
129 MU_TOG,
130
131 // Music voice iterate
132 MUV_IN,
133 MUV_DE,
134
135 // Midi
136 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
137 MI_ON, // send midi notes when music mode is enabled
138 MI_OFF, // don't send midi notes when music mode is enabled
139 #endif
140
141 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED))
142 MIDI_TONE_MIN,
143
144 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 0
145 MI_C = MIDI_TONE_MIN,
146 MI_Cs,
147 MI_Db = MI_Cs,
148 MI_D,
149 MI_Ds,
150 MI_Eb = MI_Ds,
151 MI_E,
152 MI_F,
153 MI_Fs,
154 MI_Gb = MI_Fs,
155 MI_G,
156 MI_Gs,
157 MI_Ab = MI_Gs,
158 MI_A,
159 MI_As,
160 MI_Bb = MI_As,
161 MI_B,
162 #endif
163
164 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 1
165 MI_C_1,
166 MI_Cs_1,
167 MI_Db_1 = MI_Cs_1,
168 MI_D_1,
169 MI_Ds_1,
170 MI_Eb_1 = MI_Ds_1,
171 MI_E_1,
172 MI_F_1,
173 MI_Fs_1,
174 MI_Gb_1 = MI_Fs_1,
175 MI_G_1,
176 MI_Gs_1,
177 MI_Ab_1 = MI_Gs_1,
178 MI_A_1,
179 MI_As_1,
180 MI_Bb_1 = MI_As_1,
181 MI_B_1,
182 #endif
183
184 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 2
185 MI_C_2,
186 MI_Cs_2,
187 MI_Db_2 = MI_Cs_2,
188 MI_D_2,
189 MI_Ds_2,
190 MI_Eb_2 = MI_Ds_2,
191 MI_E_2,
192 MI_F_2,
193 MI_Fs_2,
194 MI_Gb_2 = MI_Fs_2,
195 MI_G_2,
196 MI_Gs_2,
197 MI_Ab_2 = MI_Gs_2,
198 MI_A_2,
199 MI_As_2,
200 MI_Bb_2 = MI_As_2,
201 MI_B_2,
202 #endif
203
204 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 3
205 MI_C_3,
206 MI_Cs_3,
207 MI_Db_3 = MI_Cs_3,
208 MI_D_3,
209 MI_Ds_3,
210 MI_Eb_3 = MI_Ds_3,
211 MI_E_3,
212 MI_F_3,
213 MI_Fs_3,
214 MI_Gb_3 = MI_Fs_3,
215 MI_G_3,
216 MI_Gs_3,
217 MI_Ab_3 = MI_Gs_3,
218 MI_A_3,
219 MI_As_3,
220 MI_Bb_3 = MI_As_3,
221 MI_B_3,
222 #endif
223
224 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 4
225 MI_C_4,
226 MI_Cs_4,
227 MI_Db_4 = MI_Cs_4,
228 MI_D_4,
229 MI_Ds_4,
230 MI_Eb_4 = MI_Ds_4,
231 MI_E_4,
232 MI_F_4,
233 MI_Fs_4,
234 MI_Gb_4 = MI_Fs_4,
235 MI_G_4,
236 MI_Gs_4,
237 MI_Ab_4 = MI_Gs_4,
238 MI_A_4,
239 MI_As_4,
240 MI_Bb_4 = MI_As_4,
241 MI_B_4,
242 #endif
243
244 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5
245 MI_C_5,
246 MI_Cs_5,
247 MI_Db_5 = MI_Cs_5,
248 MI_D_5,
249 MI_Ds_5,
250 MI_Eb_5 = MI_Ds_5,
251 MI_E_5,
252 MI_F_5,
253 MI_Fs_5,
254 MI_Gb_5 = MI_Fs_5,
255 MI_G_5,
256 MI_Gs_5,
257 MI_Ab_5 = MI_Gs_5,
258 MI_A_5,
259 MI_As_5,
260 MI_Bb_5 = MI_As_5,
261 MI_B_5,
262 #endif
263
264 #if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5
265 MIDI_TONE_MAX = MI_B_5,
266 #elif MIDI_TONE_KEYCODE_OCTAVES > 4
267 MIDI_TONE_MAX = MI_B_4,
268 #elif MIDI_TONE_KEYCODE_OCTAVES > 3
269 MIDI_TONE_MAX = MI_B_3,
270 #elif MIDI_TONE_KEYCODE_OCTAVES > 2
271 MIDI_TONE_MAX = MI_B_2,
272 #elif MIDI_TONE_KEYCODE_OCTAVES > 1
273 MIDI_TONE_MAX = MI_B_1,
274 #elif MIDI_TONE_KEYCODE_OCTAVES > 0
275 MIDI_TONE_MAX = MI_B,
276 #endif
277
278 MIDI_OCTAVE_MIN,
279 MI_OCT_N2 = MIDI_OCTAVE_MIN,
280 MI_OCT_N1,
281 MI_OCT_0,
282 MI_OCT_1,
283 MI_OCT_2,
284 MI_OCT_3,
285 MI_OCT_4,
286 MI_OCT_5,
287 MI_OCT_6,
288 MI_OCT_7,
289 MIDI_OCTAVE_MAX = MI_OCT_7,
290 MI_OCTD, // octave down
291 MI_OCTU, // octave up
292
293 MIDI_TRANSPOSE_MIN,
294 MI_TRNS_N6 = MIDI_TRANSPOSE_MIN,
295 MI_TRNS_N5,
296 MI_TRNS_N4,
297 MI_TRNS_N3,
298 MI_TRNS_N2,
299 MI_TRNS_N1,
300 MI_TRNS_0,
301 MI_TRNS_1,
302 MI_TRNS_2,
303 MI_TRNS_3,
304 MI_TRNS_4,
305 MI_TRNS_5,
306 MI_TRNS_6,
307 MIDI_TRANSPOSE_MAX = MI_TRNS_6,
308 MI_TRNSD, // transpose down
309 MI_TRNSU, // transpose up
310
311 MIDI_VELOCITY_MIN,
312 MI_VEL_1 = MIDI_VELOCITY_MIN,
313 MI_VEL_2,
314 MI_VEL_3,
315 MI_VEL_4,
316 MI_VEL_5,
317 MI_VEL_6,
318 MI_VEL_7,
319 MI_VEL_8,
320 MI_VEL_9,
321 MI_VEL_10,
322 MIDI_VELOCITY_MAX = MI_VEL_10,
323 MI_VELD, // velocity down
324 MI_VELU, // velocity up
325
326 MIDI_CHANNEL_MIN,
327 MI_CH1 = MIDI_CHANNEL_MIN,
328 MI_CH2,
329 MI_CH3,
330 MI_CH4,
331 MI_CH5,
332 MI_CH6,
333 MI_CH7,
334 MI_CH8,
335 MI_CH9,
336 MI_CH10,
337 MI_CH11,
338 MI_CH12,
339 MI_CH13,
340 MI_CH14,
341 MI_CH15,
342 MI_CH16,
343 MIDI_CHANNEL_MAX = MI_CH16,
344 MI_CHD, // previous channel
345 MI_CHU, // next channel
346
347 MI_ALLOFF, // all notes off
348
349 MI_SUS, // sustain
350 MI_PORT, // portamento
351 MI_SOST, // sostenuto
352 MI_SOFT, // soft pedal
353 MI_LEG, // legato
354
355 MI_MOD, // modulation
356 MI_MODSD, // decrease modulation speed
357 MI_MODSU, // increase modulation speed
358 #endif // MIDI_ADVANCED
359
360 // Backlight functionality
361 BL_0,
362 BL_1,
363 BL_2,
364 BL_3,
365 BL_4,
366 BL_5,
367 BL_6,
368 BL_7,
369 BL_8,
370 BL_9,
371 BL_10,
372 BL_11,
373 BL_12,
374 BL_13,
375 BL_14,
376 BL_15,
377 BL_DEC,
378 BL_INC,
379 BL_TOGG,
380 BL_STEP,
381
382 // RGB functionality
383 RGB_TOG,
384 RGB_MOD,
385 RGB_HUI,
386 RGB_HUD,
387 RGB_SAI,
388 RGB_SAD,
389 RGB_VAI,
390 RGB_VAD,
391
392 // Left shift, open paren
393 KC_LSPO,
394
395 // Right shift, close paren
396 KC_RSPC,
397
398 // Printing
399 PRINT_ON,
400 PRINT_OFF,
401
402 // output selection
403 OUT_AUTO,
404 OUT_USB,
405 #ifdef BLUETOOTH_ENABLE
406 OUT_BT,
407 #endif
408
409 // always leave at the end
410 SAFE_RANGE
411 };
412
413 // Ability to use mods in layouts
414 #define LCTL(kc) (kc | QK_LCTL)
415 #define LSFT(kc) (kc | QK_LSFT)
416 #define LALT(kc) (kc | QK_LALT)
417 #define LGUI(kc) (kc | QK_LGUI)
418 #define RCTL(kc) (kc | QK_RCTL)
419 #define RSFT(kc) (kc | QK_RSFT)
420 #define RALT(kc) (kc | QK_RALT)
421 #define RGUI(kc) (kc | QK_RGUI)
422
423 #define HYPR(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)
424 #define MEH(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT)
425 #define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI)
426 #define ALTG(kc) (kc | QK_RCTL | QK_RALT)
427 #define SCMD(kc) (kc | QK_LGUI | QK_LSFT)
428 #define SWIN(kc) SCMD(kc)
429 #define LCA(kc) (kc | QK_LCTL | QK_LALT)
430
431 #define MOD_HYPR 0xf
432 #define MOD_MEH 0x7
433
434
435 // Aliases for shifted symbols
436 // Each key has a 4-letter code, and some have longer aliases too.
437 // While the long aliases are descriptive, the 4-letter codes
438 // make for nicer grid layouts (everything lines up), and are
439 // the preferred style for Quantum.
440 #define KC_TILD LSFT(KC_GRV) // ~
441 #define KC_TILDE KC_TILD
442
443 #define KC_EXLM LSFT(KC_1) // !
444 #define KC_EXCLAIM KC_EXLM
445
446 #define KC_AT LSFT(KC_2) // @
447
448 #define KC_HASH LSFT(KC_3) // #
449
450 #define KC_DLR LSFT(KC_4) // $
451 #define KC_DOLLAR KC_DLR
452
453 #define KC_PERC LSFT(KC_5) // %
454 #define KC_PERCENT KC_PERC
455
456 #define KC_CIRC LSFT(KC_6) // ^
457 #define KC_CIRCUMFLEX KC_CIRC
458
459 #define KC_AMPR LSFT(KC_7) // &
460 #define KC_AMPERSAND KC_AMPR
461
462 #define KC_ASTR LSFT(KC_8) // *
463 #define KC_ASTERISK KC_ASTR
464
465 #define KC_LPRN LSFT(KC_9) // (
466 #define KC_LEFT_PAREN KC_LPRN
467
468 #define KC_RPRN LSFT(KC_0) // )
469 #define KC_RIGHT_PAREN KC_RPRN
470
471 #define KC_UNDS LSFT(KC_MINS) // _
472 #define KC_UNDERSCORE KC_UNDS
473
474 #define KC_PLUS LSFT(KC_EQL) // +
475
476 #define KC_LCBR LSFT(KC_LBRC) // {
477 #define KC_LEFT_CURLY_BRACE KC_LCBR
478
479 #define KC_RCBR LSFT(KC_RBRC) // }
480 #define KC_RIGHT_CURLY_BRACE KC_RCBR
481
482 #define KC_LABK LSFT(KC_COMM) // <
483 #define KC_LEFT_ANGLE_BRACKET KC_LABK
484
485 #define KC_RABK LSFT(KC_DOT) // >
486 #define KC_RIGHT_ANGLE_BRACKET KC_RABK
487
488 #define KC_COLN LSFT(KC_SCLN) // :
489 #define KC_COLON KC_COLN
490
491 #define KC_PIPE LSFT(KC_BSLS) // |
492
493 #define KC_LT LSFT(KC_COMM) // <
494
495 #define KC_GT LSFT(KC_DOT) // >
496
497 #define KC_QUES LSFT(KC_SLSH) // ?
498 #define KC_QUESTION KC_QUES
499
500 #define KC_DQT LSFT(KC_QUOT) // "
501 #define KC_DOUBLE_QUOTE KC_DQT
502 #define KC_DQUO KC_DQT
503
504 #define KC_DELT KC_DELETE // Del key (four letter code)
505
506 // Alias for function layers than expand past FN31
507 #define FUNC(kc) (kc | QK_FUNCTION)
508
509 // Aliases
510 #define S(kc) LSFT(kc)
511 #define F(kc) FUNC(kc)
512
513 #define M(kc) (kc | QK_MACRO)
514
515 #define MACROTAP(kc) (kc | QK_MACRO | FUNC_TAP<<8)
516 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
517
518 #define KC_GESC GRAVE_ESC
519
520
521 // L-ayer, T-ap - 256 keycode max, 16 layer max
522 #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8))
523
524 #define AG_SWAP MAGIC_SWAP_ALT_GUI
525 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
526
527 #define BL_ON BL_9
528 #define BL_OFF BL_0
529
530 // GOTO layer - 16 layers max
531 // when:
532 // ON_PRESS = 1
533 // ON_RELEASE = 2
534 // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default.
535 // In fact, we changed it to assume ON_PRESS for sanity/simplicity. If needed, you can add your own
536 // keycode modeled after the old version, kept below for this.
537 /* #define TO(layer, when) (layer | QK_TO | (when << 0x4)) */
538 #define TO(layer) (layer | QK_TO | (ON_PRESS << 0x4))
539
540 // Momentary switch layer - 256 layer max
541 #define MO(layer) (layer | QK_MOMENTARY)
542
543 // Set default layer - 256 layer max
544 #define DF(layer) (layer | QK_DEF_LAYER)
545
546 // Toggle to layer - 256 layer max
547 #define TG(layer) (layer | QK_TOGGLE_LAYER)
548
549 // One-shot layer - 256 layer max
550 #define OSL(layer) (layer | QK_ONE_SHOT_LAYER)
551
552 // One-shot mod
553 #define OSM(mod) ((mod) | QK_ONE_SHOT_MOD)
554
555 // Layer tap-toggle
556 #define TT(layer) (layer | QK_LAYER_TAP_TOGGLE)
557
558 // M-od, T-ap - 256 keycode max
559 #define MT(mod, kc) (kc | QK_MOD_TAP | (((mod) & 0x1F) << 8))
560
561 #define CTL_T(kc) MT(MOD_LCTL, kc)
562 #define LCTL_T(kc) MT(MOD_LCTL, kc)
563 #define RCTL_T(kc) MT(MOD_RCTL, kc)
564
565 #define SFT_T(kc) MT(MOD_LSFT, kc)
566 #define LSFT_T(kc) MT(MOD_LSFT, kc)
567 #define RSFT_T(kc) MT(MOD_RSFT, kc)
568
569 #define ALT_T(kc) MT(MOD_LALT, kc)
570 #define LALT_T(kc) MT(MOD_LALT, kc)
571 #define RALT_T(kc) MT(MOD_RALT, kc)
572 #define ALGR_T(kc) MT(MOD_RALT, kc) // dual-function AltGR
573
574 #define GUI_T(kc) MT(MOD_LGUI, kc)
575 #define LGUI_T(kc) MT(MOD_LGUI, kc)
576 #define RGUI_T(kc) MT(MOD_RGUI, kc)
577
578 #define C_S_T(kc) MT((MOD_LCTL | MOD_LSFT), kc) // Control + Shift e.g. for gnome-terminal
579 #define MEH_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT), kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl
580 #define LCAG_T(kc) MT((MOD_LCTL | MOD_LALT | MOD_LGUI), kc) // Left control alt and gui
581 #define RCAG_T(kc) MT((MOD_RCTL | MOD_RALT | MOD_RGUI), kc) // Right control alt and gui
582 #define ALL_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI), kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
583 #define SCMD_T(kc) MT((MOD_LGUI | MOD_LSFT), kc)
584 #define SWIN_T(kc) SCMD_T(kc)
585 #define LCA_T(kc) MT((MOD_LCTL | MOD_LALT), kc) // Left control and left alt
586
587 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
588 #define KC_HYPR HYPR(KC_NO)
589 #define KC_MEH MEH(KC_NO)
590
591 #ifdef UNICODE_ENABLE
592 // For sending unicode codes.
593 // You may not send codes over 7FFF -- this supports most of UTF8.
594 // To have a key that sends out Œ, go UC(0x0152)
595 #define UNICODE(n) (n | QK_UNICODE)
596 #define UC(n) UNICODE(n)
597 #endif
598
599 #ifdef UNICODEMAP_ENABLE
600 #define X(n) (n | QK_UNICODE_MAP)
601 #endif
602
603 #endif // QUANTUM_KEYCODES_H