diff options
author | Balz Guenat <balz.guenat@gmail.com> | 2017-11-16 15:29:56 +0100 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2017-11-16 09:39:00 -0500 |
commit | 858c09f3705bd9d5d59fcd68f421273f3f40293a (patch) | |
tree | 1ecce3e8e23952e256fc2f7bf1785bd30a3c0548 /docs/feature_macros.md | |
parent | 179d64d33c5b2f881bbced97cc046949691f3757 (diff) | |
download | qmk_firmware-858c09f3705bd9d5d59fcd68f421273f3f40293a.tar.gz qmk_firmware-858c09f3705bd9d5d59fcd68f421273f3f40293a.zip |
add example keymap
Diffstat (limited to 'docs/feature_macros.md')
-rw-r--r-- | docs/feature_macros.md | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md index 050fb45aa..84b81303d 100644 --- a/docs/feature_macros.md +++ b/docs/feature_macros.md | |||
@@ -10,7 +10,7 @@ Macros allow you to send multiple keystrokes when pressing just one key. QMK has | |||
10 | 10 | ||
11 | Sometimes 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`). | 11 | Sometimes 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`). |
12 | 12 | ||
13 | For example, you could write in your `keymap.c`: | 13 | Here is an example `keymap.c` for a two-key keyboard: |
14 | 14 | ||
15 | ```c | 15 | ```c |
16 | enum custom_keycodes { | 16 | enum custom_keycodes { |
@@ -21,21 +21,26 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
21 | if (record->event.pressed) { | 21 | if (record->event.pressed) { |
22 | switch(keycode) { | 22 | switch(keycode) { |
23 | case MY_CUSTOM_MACRO: | 23 | case MY_CUSTOM_MACRO: |
24 | SEND_STRING("QMK is the best thing ever!"); | 24 | SEND_STRING("QMK is the best thing ever!"); // this is our macro! |
25 | return false; break; | 25 | return false; break; |
26 | } | 26 | } |
27 | } | 27 | } |
28 | return true; | 28 | return true; |
29 | }; | 29 | }; |
30 | ``` | ||
31 | 30 | ||
32 | To activate this macro, assign the keycode `MY_CUSTOM_MACRO` to one of your keys in your keymap. | 31 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { |
32 | [0] = { | ||
33 | {MY_CUSTOM_MACRO, KC_ESC} | ||
34 | } | ||
35 | }; | ||
36 | ``` | ||
33 | 37 | ||
34 | What happens here is this: | 38 | What happens here is this: |
35 | We first define a new custom keycode in the range not occupied by any other keycodes. | 39 | We first define a new custom keycode in the range not occupied by any other keycodes. |
36 | 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. | 40 | 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. |
37 | 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). | 41 | 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). |
38 | We return `false` to indicate to the caller that the key press we just processed need not be processed any further. | 42 | We return `false` to indicate to the caller that the key press we just processed need not be processed any further. |
43 | Finally, we define the keymap so that the first button activates our macro and the second button is just an escape button. | ||
39 | 44 | ||
40 | You might want to add more than one macro. | 45 | You might want to add more than one macro. |
41 | You can do that by adding another keycode and adding another case to the switch statement, like so: | 46 | You can do that by adding another keycode and adding another case to the switch statement, like so: |
@@ -59,6 +64,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
59 | } | 64 | } |
60 | return true; | 65 | return true; |
61 | }; | 66 | }; |
67 | |||
68 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
69 | [0] = { | ||
70 | {MY_CUSTOM_MACRO, MY_OTHER_MACRO} | ||
71 | } | ||
72 | }; | ||
62 | ``` | 73 | ``` |
63 | 74 | ||
64 | ### TAP, DOWN and UP | 75 | ### TAP, DOWN and UP |