Fix macro docs to be consistent with keyboard template (#4600)

This commit is contained in:
Drashna Jaelre 2018-12-11 09:11:35 -08:00 committed by MechMerlin
parent 930e1dfc4c
commit fb900e2ad1
1 changed files with 88 additions and 70 deletions

View File

@ -12,23 +12,27 @@ Here is an example `keymap.c` for a two-key keyboard:
```c
enum custom_keycodes {
MY_CUSTOM_MACRO = SAFE_RANGE
QMKBEST = SAFE_RANGE,
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case MY_CUSTOM_MACRO:
SEND_STRING("QMK is the best thing ever!"); // this is our macro!
return false;
case QMKBEST:
if (record->event.pressed) {
// when keycode QMKBEST is pressed
SEND_STRING("QMK is the best thing ever!");
} else {
// when keycode QMKBEST is released
}
break;
}
return true;
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = {
{MY_CUSTOM_MACRO, KC_ESC}
{QMKBEST, KC_ESC}
}
};
```
@ -37,7 +41,7 @@ What happens here is this:
We first define a new custom keycode in the range not occupied by any other keycodes.
Then we use the `process_record_user` function, which is called whenever a key is pressed or released, to check if our custom keycode has been activated.
If yes, we send the string `"QMK is the best thing ever!"` to the computer via the `SEND_STRING` macro (this is a C preprocessor macro, not to be confused with QMK macros).
We return `false` to indicate to the caller that the key press we just processed need not be processed any further.
We return `true` to indicate to the caller that the key press we just processed should continue to be processed as normal (as we didn't replace or alter the functionality).
Finally, we define the keymap so that the first button activates our macro and the second button is just an escape button.
You might want to add more than one macro.
@ -45,20 +49,34 @@ You can do that by adding another keycode and adding another case to the switch
```c
enum custom_keycodes {
MY_CUSTOM_MACRO = SAFE_RANGE,
QMKBEST = SAFE_RANGE,
QMKURL,
MY_OTHER_MACRO
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case MY_CUSTOM_MACRO:
case QMKBEST:
if (record->event.pressed) {
// when keycode QMKBEST is pressed
SEND_STRING("QMK is the best thing ever!");
return false;
case MY_OTHER_MACRO:
SEND_STRING(SS_LCTRL("ac")); // selects all and copies
return false;
} else {
// when keycode QMKBEST is released
}
break;
case QMKURL:
if (record->event.pressed) {
// when keycode QMKURL is pressed
SEND_STRING("https://qmk.fm/" SS_TAP(X_ENTER));
} else {
// when keycode QMKURL is released
}
break;
case MY_OTHER_MACRO:
if (record->event.pressed) {
SEND_STRING(SS_LCTRL("ac")); // selects all and copies
}
break;
}
return true;
};