2 Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <avr/pgmspace.h>
26 #include "action_macro.h"
31 #include "keycode_config.h"
33 /* translates key to keycode */
34 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
36 /* translates Fn keycode to action */
37 action_t keymap_fn_to_action(uint16_t keycode);
39 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
40 extern const uint16_t fn_actions[];
42 enum quantum_keycodes {
43 // Ranges used in shortucuts - not to be used directly
57 QK_FUNCTION_MAX = 0x2FFF,
59 QK_MACRO_MAX = 0x3FFF,
60 QK_LAYER_TAP = 0x4000,
61 QK_LAYER_TAP_MAX = 0x4FFF,
64 QK_MOMENTARY = 0x5100,
65 QK_MOMENTARY_MAX = 0x51FF,
66 QK_DEF_LAYER = 0x5200,
67 QK_DEF_LAYER_MAX = 0x52FF,
68 QK_TOGGLE_LAYER = 0x5300,
69 QK_TOGGLE_LAYER_MAX = 0x53FF,
70 QK_ONE_SHOT_LAYER = 0x5400,
71 QK_ONE_SHOT_LAYER_MAX = 0x54FF,
72 QK_ONE_SHOT_MOD = 0x5500,
73 QK_ONE_SHOT_MOD_MAX = 0x55FF,
74 #ifndef DISABLE_CHORDING
76 QK_CHORDING_MAX = 0x56FF,
79 QK_MOD_TAP_MAX = 0x6FFF,
82 QK_UNICODE_MAX = 0xFFFF,
85 // Loose keycodes - to be used directly
89 MAGIC_SWAP_CONTROL_CAPSLOCK,
90 MAGIC_CAPSLOCK_TO_CONTROL,
95 MAGIC_SWAP_BACKSLASH_BACKSPACE,
98 MAGIC_UNSWAP_CONTROL_CAPSLOCK,
99 MAGIC_UNCAPSLOCK_TO_CONTROL,
100 MAGIC_UNSWAP_LALT_LGUI,
101 MAGIC_UNSWAP_RALT_RGUI,
103 MAGIC_UNSWAP_GRAVE_ESC,
104 MAGIC_UNSWAP_BACKSLASH_BACKSPACE,
106 MAGIC_UNSWAP_ALT_GUI,
109 #ifndef DISABLE_LEADER
113 // Audio on/off/toggle
118 // Music mode on/off/toggle
123 // Music voice iterate
131 // Backlight functionality
153 // Left shift, open paren
156 // Right shift, close paren
160 // Ability to use mods in layouts
161 #define LCTL(kc) (kc | QK_LCTL)
162 #define LSFT(kc) (kc | QK_LSFT)
163 #define LALT(kc) (kc | QK_LALT)
164 #define LGUI(kc) (kc | QK_LGUI)
165 #define RCTL(kc) (kc | QK_RCTL)
166 #define RSFT(kc) (kc | QK_RSFT)
167 #define RALT(kc) (kc | QK_RALT)
168 #define RGUI(kc) (kc | QK_RGUI)
170 #define HYPR(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)
171 #define MEH(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT)
172 #define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI)
178 // Aliases for shifted symbols
179 // Each key has a 4-letter code, and some have longer aliases too.
180 // While the long aliases are descriptive, the 4-letter codes
181 // make for nicer grid layouts (everything lines up), and are
182 // the preferred style for Quantum.
183 #define KC_TILD LSFT(KC_GRV) // ~
184 #define KC_TILDE KC_TILD
186 #define KC_EXLM LSFT(KC_1) // !
187 #define KC_EXCLAIM KC_EXLM
189 #define KC_AT LSFT(KC_2) // @
191 #define KC_HASH LSFT(KC_3) // #
193 #define KC_DLR LSFT(KC_4) // $
194 #define KC_DOLLAR KC_DLR
196 #define KC_PERC LSFT(KC_5) // %
197 #define KC_PERCENT KC_PERC
199 #define KC_CIRC LSFT(KC_6) // ^
200 #define KC_CIRCUMFLEX KC_CIRC
202 #define KC_AMPR LSFT(KC_7) // &
203 #define KC_AMPERSAND KC_AMPR
205 #define KC_ASTR LSFT(KC_8) // *
206 #define KC_ASTERISK KC_ASTR
208 #define KC_LPRN LSFT(KC_9) // (
209 #define KC_LEFT_PAREN KC_LPRN
211 #define KC_RPRN LSFT(KC_0) // )
212 #define KC_RIGHT_PAREN KC_RPRN
214 #define KC_UNDS LSFT(KC_MINS) // _
215 #define KC_UNDERSCORE KC_UNDS
217 #define KC_PLUS LSFT(KC_EQL) // +
219 #define KC_LCBR LSFT(KC_LBRC) // {
220 #define KC_LEFT_CURLY_BRACE KC_LCBR
222 #define KC_RCBR LSFT(KC_RBRC) // }
223 #define KC_RIGHT_CURLY_BRACE KC_RCBR
225 #define KC_LABK LSFT(KC_COMM) // <
226 #define KC_LEFT_ANGLE_BRACKET KC_LABK
228 #define KC_RABK LSFT(KC_DOT) // >
229 #define KC_RIGHT_ANGLE_BRACKET KC_RABK
231 #define KC_COLN LSFT(KC_SCLN) // :
232 #define KC_COLON KC_COLN
234 #define KC_PIPE LSFT(KC_BSLS) // |
236 #define KC_LT LSFT(KC_COMM) // <
238 #define KC_GT LSFT(KC_DOT) // >
240 #define KC_QUES LSFT(KC_SLSH) // ?
241 #define KC_QUESTION KC_QUES
243 #define KC_DQT LSFT(KC_QUOT) // "
244 #define KC_DOUBLE_QUOTE KC_DQT
245 #define KC_DQUO KC_DQT
247 #define KC_DELT KC_DELETE // Del key (four letter code)
249 // Alias for function layers than expand past FN31
250 #define FUNC(kc) (kc | QK_FUNCTION)
253 #define S(kc) LSFT(kc)
254 #define F(kc) FUNC(kc)
256 #define M(kc) (kc | QK_MACRO)
258 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
260 // L-ayer, T-ap - 256 keycode max, 16 layer max
261 #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8))
263 #define AG_SWAP MAGIC_SWAP_ALT_GUI
264 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
269 // GOTO layer - 16 layers max
273 // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default.
274 #define TO(layer, when) (layer | QK_TO | (when << 0x4))
276 // Momentary switch layer - 256 layer max
277 #define MO(layer) (layer | QK_MOMENTARY)
279 // Set default layer - 256 layer max
280 #define DF(layer) (layer | QK_DEF_LAYER)
282 // Toggle to layer - 256 layer max
283 #define TG(layer) (layer | QK_TOGGLE_LAYER)
285 // One-shot layer - 256 layer max
286 #define OSL(layer) (layer | QK_ONE_SHOT_LAYER)
289 #define OSM(layer) (layer | QK_ONE_SHOT_MOD)
291 // M-od, T-ap - 256 keycode max
292 #define MT(mod, kc) (kc | QK_MOD_TAP | ((mod & 0xF) << 8))
293 #define CTL_T(kc) MT(MOD_LCTL, kc)
294 #define SFT_T(kc) MT(MOD_LSFT, kc)
295 #define ALT_T(kc) MT(MOD_LALT, kc)
296 #define GUI_T(kc) MT(MOD_LGUI, kc)
297 #define C_S_T(kc) MT(MOD_LCTL | MOD_LSFT, kc) // Control + Shift e.g. for gnome-terminal
298 #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
299 #define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc) // Left control alt and gui
300 #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/
302 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
303 #define KC_HYPR HYPR(KC_NO)
304 #define KC_MEH MEH(KC_NO)
306 #ifdef UNICODE_ENABLE
307 // For sending unicode codes.
308 // You may not send codes over 7FFF -- this supports most of UTF8.
309 // To have a key that sends out Œ, go UC(0x0152)
310 #define UNICODE(n) (n | QK_UNICODE)
311 #define UC(n) UNICODE(n)