aboutsummaryrefslogtreecommitdiff
path: root/docs/feature_macros.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/feature_macros.md')
-rw-r--r--docs/feature_macros.md89
1 files changed, 46 insertions, 43 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md
index 1c7705a51..acd40d1bf 100644
--- a/docs/feature_macros.md
+++ b/docs/feature_macros.md
@@ -6,34 +6,34 @@ Macros allow you to send multiple keystrokes when pressing just one key. QMK has
6 6
7## The New Way: `SEND_STRING()` & `process_record_user` 7## The New Way: `SEND_STRING()` & `process_record_user`
8 8
9Sometimes you just want a key to type out words or phrases. For the most common situations we've provided `SEND_STRING()`, which will type out your string (i.e. a sequence of characters) for you. All ASCII characters that are easily translated to a keycode are supported (e.g. `\n\t`). 9Sometimes you want a key to type out words or phrases. For the most common situations, we've provided `SEND_STRING()`, which will type out a string (i.e. a sequence of characters) for you. All ASCII characters that are easily translatable to a keycode are supported (e.g. `qmk 123\n\t`).
10 10
11Here is an example `keymap.c` for a two-key keyboard: 11Here is an example `keymap.c` for a two-key keyboard:
12 12
13```c 13```c
14enum custom_keycodes { 14enum custom_keycodes {
15 QMKBEST = SAFE_RANGE, 15 QMKBEST = SAFE_RANGE,
16}; 16};
17 17
18bool process_record_user(uint16_t keycode, keyrecord_t *record) { 18bool process_record_user(uint16_t keycode, keyrecord_t *record) {
19 switch (keycode) { 19 switch (keycode) {
20 case QMKBEST: 20 case QMKBEST:
21 if (record->event.pressed) { 21 if (record->event.pressed) {
22 // when keycode QMKBEST is pressed 22 // when keycode QMKBEST is pressed
23 SEND_STRING("QMK is the best thing ever!"); 23 SEND_STRING("QMK is the best thing ever!");
24 } else { 24 } else {
25 // when keycode QMKBEST is released 25 // when keycode QMKBEST is released
26 } 26 }
27 break; 27 break;
28 28 }
29 } 29 return true;
30 return true;
31}; 30};
32 31
33const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 32const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
34 [0] = { 33 [0] = {
35 {QMKBEST, KC_ESC} 34 {QMKBEST, KC_ESC},
36 } 35 // ...
36 },
37}; 37};
38``` 38```
39 39
@@ -49,42 +49,45 @@ You can do that by adding another keycode and adding another case to the switch
49 49
50```c 50```c
51enum custom_keycodes { 51enum custom_keycodes {
52 QMKBEST = SAFE_RANGE, 52 QMKBEST = SAFE_RANGE,
53 QMKURL, 53 QMKURL,
54 MY_OTHER_MACRO 54 MY_OTHER_MACRO,
55}; 55};
56 56
57bool process_record_user(uint16_t keycode, keyrecord_t *record) { 57bool process_record_user(uint16_t keycode, keyrecord_t *record) {
58 switch (keycode) { 58 switch (keycode) {
59 case QMKBEST: 59 case QMKBEST:
60 if (record->event.pressed) { 60 if (record->event.pressed) {
61 // when keycode QMKBEST is pressed 61 // when keycode QMKBEST is pressed
62 SEND_STRING("QMK is the best thing ever!"); 62 SEND_STRING("QMK is the best thing ever!");
63 } else { 63 } else {
64 // when keycode QMKBEST is released 64 // when keycode QMKBEST is released
65 } 65 }
66 break; 66 break;
67
67 case QMKURL: 68 case QMKURL:
68 if (record->event.pressed) { 69 if (record->event.pressed) {
69 // when keycode QMKURL is pressed 70 // when keycode QMKURL is pressed
70 SEND_STRING("https://qmk.fm/\n"); 71 SEND_STRING("https://qmk.fm/\n");
71 } else { 72 } else {
72 // when keycode QMKURL is released 73 // when keycode QMKURL is released
73 } 74 }
74 break; 75 break;
76
75 case MY_OTHER_MACRO: 77 case MY_OTHER_MACRO:
76 if (record->event.pressed) { 78 if (record->event.pressed) {
77 SEND_STRING(SS_LCTL("ac")); // selects all and copies 79 SEND_STRING(SS_LCTL("ac")); // selects all and copies
78 } 80 }
79 break; 81 break;
80 } 82 }
81 return true; 83 return true;
82}; 84};
83 85
84const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 86const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
85 [0] = { 87 [0] = {
86 {MY_CUSTOM_MACRO, MY_OTHER_MACRO} 88 {MY_CUSTOM_MACRO, MY_OTHER_MACRO},
87 } 89 // ...
90 },
88}; 91};
89``` 92```
90 93