1
0
Fork 0
forked from forks/qmk_firmware

Macro keycode name refactoring (#18958)

This commit is contained in:
Nick Brassel 2022-11-05 23:22:11 +11:00 committed by GitHub
parent fe00c80211
commit 4d33f356a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 243 additions and 116 deletions

View file

@ -3,131 +3,227 @@
"0x7700": {
"group": "macro",
"key": "MACRO_0"
"key": "QK_MACRO_0",
"aliases": [
"MC_0"
]
},
"0x7701": {
"group": "macro",
"key": "MACRO_1"
"key": "QK_MACRO_1",
"aliases": [
"MC_1"
]
},
"0x7702": {
"group": "macro",
"key": "MACRO_2"
"key": "QK_MACRO_2",
"aliases": [
"MC_2"
]
},
"0x7703": {
"group": "macro",
"key": "MACRO_3"
"key": "QK_MACRO_3",
"aliases": [
"MC_3"
]
},
"0x7704": {
"group": "macro",
"key": "MACRO_4"
"key": "QK_MACRO_4",
"aliases": [
"MC_4"
]
},
"0x7705": {
"group": "macro",
"key": "MACRO_5"
"key": "QK_MACRO_5",
"aliases": [
"MC_5"
]
},
"0x7706": {
"group": "macro",
"key": "MACRO_6"
"key": "QK_MACRO_6",
"aliases": [
"MC_6"
]
},
"0x7707": {
"group": "macro",
"key": "MACRO_7"
"key": "QK_MACRO_7",
"aliases": [
"MC_7"
]
},
"0x7708": {
"group": "macro",
"key": "MACRO_8"
"key": "QK_MACRO_8",
"aliases": [
"MC_8"
]
},
"0x7709": {
"group": "macro",
"key": "MACRO_9"
"key": "QK_MACRO_9",
"aliases": [
"MC_9"
]
},
"0x770A": {
"group": "macro",
"key": "MACRO_10"
"key": "QK_MACRO_10",
"aliases": [
"MC_10"
]
},
"0x770B": {
"group": "macro",
"key": "MACRO_11"
"key": "QK_MACRO_11",
"aliases": [
"MC_11"
]
},
"0x770C": {
"group": "macro",
"key": "MACRO_12"
"key": "QK_MACRO_12",
"aliases": [
"MC_12"
]
},
"0x770D": {
"group": "macro",
"key": "MACRO_13"
"key": "QK_MACRO_13",
"aliases": [
"MC_13"
]
},
"0x770E": {
"group": "macro",
"key": "MACRO_14"
"key": "QK_MACRO_14",
"aliases": [
"MC_14"
]
},
"0x770F": {
"group": "macro",
"key": "MACRO_15"
"key": "QK_MACRO_15",
"aliases": [
"MC_15"
]
},
"0x7710": {
"group": "macro",
"key": "MACRO_16"
"key": "QK_MACRO_16",
"aliases": [
"MC_16"
]
},
"0x7711": {
"group": "macro",
"key": "MACRO_17"
"key": "QK_MACRO_17",
"aliases": [
"MC_17"
]
},
"0x7712": {
"group": "macro",
"key": "MACRO_18"
"key": "QK_MACRO_18",
"aliases": [
"MC_18"
]
},
"0x7713": {
"group": "macro",
"key": "MACRO_19"
"key": "QK_MACRO_19",
"aliases": [
"MC_19"
]
},
"0x7714": {
"group": "macro",
"key": "MACRO_20"
"key": "QK_MACRO_20",
"aliases": [
"MC_20"
]
},
"0x7715": {
"group": "macro",
"key": "MACRO_21"
"key": "QK_MACRO_21",
"aliases": [
"MC_21"
]
},
"0x7716": {
"group": "macro",
"key": "MACRO_22"
"key": "QK_MACRO_22",
"aliases": [
"MC_22"
]
},
"0x7717": {
"group": "macro",
"key": "MACRO_23"
"key": "QK_MACRO_23",
"aliases": [
"MC_23"
]
},
"0x7718": {
"group": "macro",
"key": "MACRO_24"
"key": "QK_MACRO_24",
"aliases": [
"MC_24"
]
},
"0x7719": {
"group": "macro",
"key": "MACRO_25"
"key": "QK_MACRO_25",
"aliases": [
"MC_25"
]
},
"0x771A": {
"group": "macro",
"key": "MACRO_26"
"key": "QK_MACRO_26",
"aliases": [
"MC_26"
]
},
"0x771B": {
"group": "macro",
"key": "MACRO_27"
"key": "QK_MACRO_27",
"aliases": [
"MC_27"
]
},
"0x771C": {
"group": "macro",
"key": "MACRO_28"
"key": "QK_MACRO_28",
"aliases": [
"MC_28"
]
},
"0x771D": {
"group": "macro",
"key": "MACRO_29"
"key": "QK_MACRO_29",
"aliases": [
"MC_29"
]
},
"0x771E": {
"group": "macro",
"key": "MACRO_30"
"key": "QK_MACRO_30",
"aliases": [
"MC_30"
]
},
"0x771F": {
"group": "macro",
"key": "MACRO_31"
"key": "QK_MACRO_31",
"aliases": [
"MC_31"
]
}
}
}
}

View file

@ -56,19 +56,19 @@ You can now define up to 32 macros in your `keymap.json` file, as used by [QMK C
"keyboard": "handwired/my_macropad",
"keymap": "my_keymap",
"macros": [
[ // first listed is MACRO_0...
[ // first listed is QK_MACRO_0...
{"action":"down", "keycodes": ["LSFT"]},
"hello world1",
{"action": "up","keycodes": ["LSFT"]}
],
[ // ...then MACRO_1...
[ // ...then QK_MACRO_1...
{"action":"tap", "keycodes": ["LCTL", "LALT", "DEL"]}
],
[ // ...then MACRO_2...
[ // ...then QK_MACRO_2...
"ding!",
{"action":"beep"}
],
[ // ...and MACRO_3.
[ // ...and QK_MACRO_3.
{"action":"tap", "keycodes": ["F1"]},
{"action":"delay", "duration": "1000"},
{"action":"tap", "keycodes": ["PGDN"]}
@ -76,7 +76,7 @@ You can now define up to 32 macros in your `keymap.json` file, as used by [QMK C
],
"layout": "LAYOUT_all",
"layers": [
["MACRO_0", "MACRO_1", "MACRO_2", "MACRO_3"]
["QK_MACRO_0", "QK_MACRO_1", "QK_MACRO_2", "QK_MACRO_3"]
]
}
```

View file

@ -122,26 +122,26 @@ There is a way to support custom keycodes: if the logic for a custom keycode is
```c
enum custom_keycodes {
MACRO_1 = SAFE_RANGE,
MACRO_2,
MACRO_3
CUSTOM_1 = SAFE_RANGE,
CUSTOM_2,
CUSTOM_3
};
...
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case MACRO_1:
case CUSTOM_1:
if (record->event.pressed) {
SEND_STRING("This is macro #1.");
SEND_STRING("This is custom keycode #1.");
}
return false;
case MACRO_2:
case CUSTOM_2:
if (record->event.pressed) {
SEND_STRING("This is macro #2.");
SEND_STRING("This is custom keycode #2.");
}
return false;
case MACRO_3:
case CUSTOM_3:
if (record->event.pressed) {
SEND_STRING("This is macro #3.");
SEND_STRING("This is custom keycode #3.");
}
return false;
}
@ -153,9 +153,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
```c
enum keyboard_keycodes {
MACRO_1 = SAFE_RANGE,
MACRO_2,
MACRO_3,
CUSTOM_1 = SAFE_RANGE,
CUSTOM_2,
CUSTOM_3,
NEW_SAFE_RANGE // Important!
};
```
@ -165,19 +165,19 @@ enum keyboard_keycodes {
```c
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case MACRO_1:
case CUSTOM_1:
if (record->event.pressed) {
SEND_STRING("This is macro #1.");
SEND_STRING("This is custom keycode #1.");
}
return false;
case MACRO_2:
case CUSTOM_2:
if (record->event.pressed) {
SEND_STRING("This is macro #2.");
SEND_STRING("This is custom keycode #2.");
}
return false;
case MACRO_3:
case CUSTOM_3:
if (record->event.pressed) {
SEND_STRING("This is macro #3.");
SEND_STRING("This is custom keycode #3.");
}
return false;
}

View file

@ -33,7 +33,7 @@ You can define up to 32 macros in a `keymap.json` file, as used by [Configurator
],
"layout": "LAYOUT_all",
"layers": [
["MACRO_0", "MACRO_1", "MACRO_2", "MACRO_3"]
["QK_MACRO_0", "QK_MACRO_1", "QK_MACRO_2", "QK_MACRO_3"]
]
}
```
@ -52,7 +52,7 @@ If you type in a language other than English, or use a non-QWERTY layout like Co
],
"layout": "LAYOUT_all",
"layers": [
["MACRO_0"]
["QK_MACRO_0"]
]
}
```
@ -199,7 +199,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
#### Advanced Macros
In addition to the `process_record_user()` function, is the `post_process_record_user()` function. This runs after `process_record` and can be used to do things after a keystroke has been sent. This is useful if you want to have a key pressed before and released after a normal key, for instance.
In addition to the `process_record_user()` function, is the `post_process_record_user()` function. This runs after `process_record` and can be used to do things after a keystroke has been sent. This is useful if you want to have a key pressed before and released after a normal key, for instance.
In this example, we modify most normal keypresses so that `F22` is pressed before the keystroke is normally sent, and release it __only after__ it's been released.

View file

@ -127,26 +127,26 @@ enum layer_names {
```c
enum custom_keycodes {
MACRO_1 = SAFE_RANGE,
MACRO_2,
MACRO_3
CUSTOM_1 = SAFE_RANGE,
CUSTOM_2,
CUSTOM_3
};
...
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case MACRO_1:
case CUSTOM_1:
if (record->event.pressed) {
SEND_STRING("This is macro #1.");
SEND_STRING("This is custom keycode #1.");
}
return false;
case MACRO_2:
case CUSTOM_2:
if (record->event.pressed) {
SEND_STRING("This is macro #2.");
SEND_STRING("This is custom keycode #2.");
}
return false;
case MACRO_3:
case CUSTOM_3:
if (record->event.pressed) {
SEND_STRING("This is macro #3.");
SEND_STRING("This is custom keycode #3.");
}
return false;
}
@ -158,9 +158,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
```c
enum keyboard_keycodes {
MACRO_1 = SAFE_RANGE,
MACRO_2,
MACRO_3,
CUSTOM_1 = SAFE_RANGE,
CUSTOM_2,
CUSTOM_3,
NEW_SAFE_RANGE // 重要!
};
```
@ -170,19 +170,19 @@ enum keyboard_keycodes {
```c
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case MACRO_1:
case CUSTOM_1:
if (record->event.pressed) {
SEND_STRING("This is macro #1.");
SEND_STRING("This is custom keycode #1.");
}
return false;
case MACRO_2:
case CUSTOM_2:
if (record->event.pressed) {
SEND_STRING("This is macro #2.");
SEND_STRING("This is custom keycode #2.");
}
return false;
case MACRO_3:
case CUSTOM_3:
if (record->event.pressed) {
SEND_STRING("This is macro #3.");
SEND_STRING("This is custom keycode #3.");
}
return false;
}

View file

@ -2,7 +2,7 @@
"keyboard": "handwired/pytest/basic",
"keymap": "default_json",
"layout": "LAYOUT_ortho_1x1",
"layers": [["MACRO_0"]],
"layers": [["QK_MACRO_0"]],
"macros": [
[
"Hello, World!",

View file

@ -42,7 +42,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, _______,
KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS),S(KC_NUBS),KC_HOME, KC_END, _______,
_______, _______, _______, MACRO_1, _______, MACRO_0, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
_______, _______, _______, MC_1, _______, MC_0, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
),
[_RAISE] = LAYOUT(
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, _______,

View file

@ -266,7 +266,7 @@ def generate_c(keymap_json):
new_macro = "".join(macro)
new_macro = new_macro.replace('""', '')
macro_txt.append(f' case MACRO_{i}:')
macro_txt.append(f' case QK_MACRO_{i}:')
macro_txt.append(f' SEND_STRING({new_macro});')
macro_txt.append(' return false;')

View file

@ -150,8 +150,8 @@ def test_json2c():
def test_json2c_macros():
result = check_subcommand("json2c", 'keyboards/handwired/pytest/macro/keymaps/default/keymap.json')
check_returncode(result)
assert 'LAYOUT_ortho_1x1(MACRO_0)' in result.stdout
assert 'case MACRO_0:' in result.stdout
assert 'LAYOUT_ortho_1x1(QK_MACRO_0)' in result.stdout
assert 'case QK_MACRO_0:' in result.stdout
assert 'SEND_STRING("Hello, World!"SS_TAP(X_ENTER));' in result.stdout

View file

@ -582,38 +582,38 @@ enum qk_keycode_defines {
QK_STENO_GEMINI = 0x74F1,
QK_STENO_COMB = 0x74F2,
QK_STENO_COMB_MAX = 0x74FC,
MACRO_0 = 0x7700,
MACRO_1 = 0x7701,
MACRO_2 = 0x7702,
MACRO_3 = 0x7703,
MACRO_4 = 0x7704,
MACRO_5 = 0x7705,
MACRO_6 = 0x7706,
MACRO_7 = 0x7707,
MACRO_8 = 0x7708,
MACRO_9 = 0x7709,
MACRO_10 = 0x770A,
MACRO_11 = 0x770B,
MACRO_12 = 0x770C,
MACRO_13 = 0x770D,
MACRO_14 = 0x770E,
MACRO_15 = 0x770F,
MACRO_16 = 0x7710,
MACRO_17 = 0x7711,
MACRO_18 = 0x7712,
MACRO_19 = 0x7713,
MACRO_20 = 0x7714,
MACRO_21 = 0x7715,
MACRO_22 = 0x7716,
MACRO_23 = 0x7717,
MACRO_24 = 0x7718,
MACRO_25 = 0x7719,
MACRO_26 = 0x771A,
MACRO_27 = 0x771B,
MACRO_28 = 0x771C,
MACRO_29 = 0x771D,
MACRO_30 = 0x771E,
MACRO_31 = 0x771F,
QK_MACRO_0 = 0x7700,
QK_MACRO_1 = 0x7701,
QK_MACRO_2 = 0x7702,
QK_MACRO_3 = 0x7703,
QK_MACRO_4 = 0x7704,
QK_MACRO_5 = 0x7705,
QK_MACRO_6 = 0x7706,
QK_MACRO_7 = 0x7707,
QK_MACRO_8 = 0x7708,
QK_MACRO_9 = 0x7709,
QK_MACRO_10 = 0x770A,
QK_MACRO_11 = 0x770B,
QK_MACRO_12 = 0x770C,
QK_MACRO_13 = 0x770D,
QK_MACRO_14 = 0x770E,
QK_MACRO_15 = 0x770F,
QK_MACRO_16 = 0x7710,
QK_MACRO_17 = 0x7711,
QK_MACRO_18 = 0x7712,
QK_MACRO_19 = 0x7713,
QK_MACRO_20 = 0x7714,
QK_MACRO_21 = 0x7715,
QK_MACRO_22 = 0x7716,
QK_MACRO_23 = 0x7717,
QK_MACRO_24 = 0x7718,
QK_MACRO_25 = 0x7719,
QK_MACRO_26 = 0x771A,
QK_MACRO_27 = 0x771B,
QK_MACRO_28 = 0x771C,
QK_MACRO_29 = 0x771D,
QK_MACRO_30 = 0x771E,
QK_MACRO_31 = 0x771F,
BL_ON = 0x7800,
BL_OFF = 0x7801,
BL_DEC = 0x7802,
@ -1000,6 +1000,38 @@ enum qk_keycode_defines {
CK_UP = CLICKY_UP,
CK_DOWN = CLICKY_DOWN,
CK_RST = CLICKY_RESET,
MC_0 = QK_MACRO_0,
MC_1 = QK_MACRO_1,
MC_2 = QK_MACRO_2,
MC_3 = QK_MACRO_3,
MC_4 = QK_MACRO_4,
MC_5 = QK_MACRO_5,
MC_6 = QK_MACRO_6,
MC_7 = QK_MACRO_7,
MC_8 = QK_MACRO_8,
MC_9 = QK_MACRO_9,
MC_10 = QK_MACRO_10,
MC_11 = QK_MACRO_11,
MC_12 = QK_MACRO_12,
MC_13 = QK_MACRO_13,
MC_14 = QK_MACRO_14,
MC_15 = QK_MACRO_15,
MC_16 = QK_MACRO_16,
MC_17 = QK_MACRO_17,
MC_18 = QK_MACRO_18,
MC_19 = QK_MACRO_19,
MC_20 = QK_MACRO_20,
MC_21 = QK_MACRO_21,
MC_22 = QK_MACRO_22,
MC_23 = QK_MACRO_23,
MC_24 = QK_MACRO_24,
MC_25 = QK_MACRO_25,
MC_26 = QK_MACRO_26,
MC_27 = QK_MACRO_27,
MC_28 = QK_MACRO_28,
MC_29 = QK_MACRO_29,
MC_30 = QK_MACRO_30,
MC_31 = QK_MACRO_31,
RGB_MOD = RGB_MODE_FORWARD,
RGB_RMOD = RGB_MODE_REVERSE,
RGB_M_P = RGB_MODE_PLAIN,
@ -1108,8 +1140,7 @@ enum qk_keycode_defines {
#define IS_PROGRAMMABLE_BUTTON_KEYCODE(code) ((code) >= QK_PROGRAMMABLE_BUTTON_1 && (code) <= QK_PROGRAMMABLE_BUTTON_32)
#define IS_AUDIO_KEYCODE(code) ((code) >= AU_ON && (code) <= MUV_DE)
#define IS_STENO_KEYCODE(code) ((code) >= QK_STENO_BOLT && (code) <= QK_STENO_COMB_MAX)
#define IS_MACRO_KEYCODE(code) ((code) >= MACRO_0 && (code) <= MACRO_31)
#define IS_MACRO_KEYCODE(code) ((code) >= QK_MACRO_0 && (code) <= QK_MACRO_31)
#define IS_BACKLIGHT_KEYCODE(code) ((code) >= BL_ON && (code) <= BL_BRTG)
#define IS_RGB_KEYCODE(code) ((code) >= RGB_TOG && (code) <= RGB_MODE_TWINKLE)
#define IS_QUANTUM_KEYCODE(code) ((code) >= QK_BOOTLOADER && (code) <= QK_AUTOCORRECT_TOGGLE)