From 02781979d6af096e8adb6bb02af7639b73c8f267 Mon Sep 17 00:00:00 2001 From: Konstantin Đorđević Date: Sat, 20 Jun 2020 22:58:48 +0200 Subject: [Docs] Improve Unicode documentation (#8676) --- docs/feature_macros.md | 89 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'docs/feature_macros.md') 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 ## The New Way: `SEND_STRING()` & `process_record_user` -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`). +Sometimes 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`). Here is an example `keymap.c` for a two-key keyboard: ```c enum custom_keycodes { - QMKBEST = SAFE_RANGE, + QMKBEST = SAFE_RANGE, }; bool process_record_user(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { + switch (keycode) { 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; + 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] = { - {QMKBEST, KC_ESC} - } + [0] = { + {QMKBEST, KC_ESC}, + // ... + }, }; ``` @@ -49,42 +49,45 @@ You can do that by adding another keycode and adding another case to the switch ```c enum custom_keycodes { - QMKBEST = SAFE_RANGE, - QMKURL, - MY_OTHER_MACRO + QMKBEST = SAFE_RANGE, + QMKURL, + MY_OTHER_MACRO, }; bool process_record_user(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { + switch (keycode) { 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; + if (record->event.pressed) { + // when keycode QMKBEST is pressed + SEND_STRING("QMK is the best thing ever!"); + } else { + // when keycode QMKBEST is released + } + break; + case QMKURL: - if (record->event.pressed) { - // when keycode QMKURL is pressed - SEND_STRING("https://qmk.fm/\n"); - } else { - // when keycode QMKURL is released - } - break; + if (record->event.pressed) { + // when keycode QMKURL is pressed + SEND_STRING("https://qmk.fm/\n"); + } else { + // when keycode QMKURL is released + } + break; + case MY_OTHER_MACRO: - if (record->event.pressed) { - SEND_STRING(SS_LCTL("ac")); // selects all and copies - } - break; - } - return true; + if (record->event.pressed) { + SEND_STRING(SS_LCTL("ac")); // selects all and copies + } + break; + } + return true; }; const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = { - {MY_CUSTOM_MACRO, MY_OTHER_MACRO} - } + [0] = { + {MY_CUSTOM_MACRO, MY_OTHER_MACRO}, + // ... + }, }; ``` -- cgit v1.2.3-70-g09d2