1
0
Fork 0

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

@ -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;
}