You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
6.2 KiB

  1. # Send String
  2. The Send String API is part of QMK's macro system. It allows for sequences of keystrokes to be sent automatically.
  3. The full ASCII character set is supported, along with all of the keycodes in the Basic Keycode range (as these are the only ones that will actually be sent to the host).
  4. ?> Unicode characters are **not** supported with this API -- see the [Unicode](feature_unicode.md) feature instead.
  5. ## Usage
  6. Send String is enabled by default, so there is usually no need for any special setup. However, if it is disabled, add the following to your `rules.mk`:
  7. ```make
  8. SEND_STRING_ENABLE = yes
  9. ```
  10. ## Basic Configuration
  11. Add the following to your `config.h`:
  12. |Define |Default |Description |
  13. |-----------------|----------------|------------------------------------------------------------------------------------------------------------|
  14. |`SENDSTRING_BELL`|*Not defined* |If the [Audio](feature_audio.md) feature is enabled, the `\a` character (ASCII `BEL`) will beep the speaker.|
  15. |`BELL_SOUND` |`TERMINAL_SOUND`|The song to play when the `\a` character is encountered. By default, this is an eighth note of C5. |
  16. ## Keycodes
  17. The Send String functions accept C string literals, but specific keycodes can be injected with the below macros. All of the keycodes in the [Basic Keycode range](keycodes_basic.md) are supported (as these are the only ones that will actually be sent to the host), but with an `X_` prefix instead of `KC_`.
  18. |Macro |Description |
  19. |--------------|-------------------------------------------------------------------|
  20. |`SS_TAP(x)` |Send a keydown, then keyup, event for the given Send String keycode|
  21. |`SS_DOWN(x)` |Send a keydown event for the given Send String keycode |
  22. |`SS_UP(x)` |Send a keyup event for the given Send String keycode |
  23. |`SS_DELAY(ms)`|Wait for `ms` milliseconds |
  24. The following characters are also mapped to their respective keycodes for convenience:
  25. |Character|Hex |ASCII|Keycode |
  26. |---------|------|-----|--------------|
  27. |`\b` |`\x08`|`BS` |`KC_BACKSPACE`|
  28. |`\e` |`\x09`|`ESC`|`KC_ESCAPE` |
  29. |`\n` |`\x0A`|`LF` |`KC_ENTER` |
  30. |`\t` |`\x1B`|`TAB`|`KC_TAB` |
  31. | |`\x7F`|`DEL`|`KC_DELETE` |
  32. ### Language Support
  33. By default, Send String assumes your OS keyboard layout is set to US ANSI. If you are using a different keyboard layout, you can [override the lookup tables used to convert ASCII characters to keystrokes](reference_keymap_extras.md#sendstring-support).
  34. ## Examples
  35. ### Hello World
  36. A simple custom keycode which types out "Hello, world!" and the Enter key when pressed.
  37. Add the following to your `keymap.c`:
  38. ```c
  39. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  40. switch (keycode) {
  41. case SS_HELLO:
  42. if (record->event.pressed) {
  43. SEND_STRING("Hello, world!\n");
  44. }
  45. return false;
  46. }
  47. return true;
  48. }
  49. ```
  50. ### Keycode Injection
  51. This example types out opening and closing curly braces, then taps the left arrow key to move the cursor between the two.
  52. ```c
  53. SEND_STRING("{}" SS_TAP(X_LEFT));
  54. ```
  55. This example types Ctrl+A, then Ctrl+C, without releasing Ctrl.
  56. ```c
  57. SEND_STRING(SS_LCTL("ac"));
  58. ```
  59. ## API
  60. ### `void send_string(const char *string)`
  61. Type out a string of ASCII characters.
  62. This function simply calls `send_string_with_delay(string, 0)`.
  63. #### Arguments
  64. - `const char *string`
  65. The string to type out.
  66. ---
  67. ### `void send_string_with_delay(const char *string, uint8_t interval)`
  68. Type out a string of ASCII characters, with a delay between each character.
  69. #### Arguments
  70. - `const char *string`
  71. The string to type out.
  72. - `uint8_t interval`
  73. The amount of time, in milliseconds, to wait before typing the next character.
  74. ---
  75. ### `void send_string_P(const char *string)`
  76. Type out a PROGMEM string of ASCII characters.
  77. On ARM devices, this function is simply an alias for `send_string_with_delay(string, 0)`.
  78. #### Arguments
  79. - `const char *string`
  80. The string to type out.
  81. ---
  82. ### `void send_string_with_delay_P(const char *string, uint8_t interval)`
  83. Type out a PROGMEM string of ASCII characters, with a delay between each character.
  84. On ARM devices, this function is simply an alias for `send_string_with_delay(string, interval)`.
  85. #### Arguments
  86. - `const char *string`
  87. The string to type out.
  88. - `uint8_t interval`
  89. The amount of time, in milliseconds, to wait before typing the next character.
  90. ---
  91. ### `void send_char(char ascii_code)`
  92. Type out an ASCII character.
  93. #### Arguments
  94. - `char ascii_code`
  95. The character to type.
  96. ---
  97. ### `void send_dword(uint32_t number)`
  98. Type out an eight digit (unsigned 32-bit) hexadecimal value.
  99. The format is `[0-9a-f]{8}`, eg. `00000000` through `ffffffff`.
  100. #### Arguments
  101. - `uint32_t number`
  102. The value to type, from 0 to 4,294,967,295.
  103. ---
  104. ### `void send_word(uint16_t number)`
  105. Type out a four digit (unsigned 16-bit) hexadecimal value.
  106. The format is `[0-9a-f]{4}`, eg. `0000` through `ffff`.
  107. #### Arguments
  108. - `uint16_t number`
  109. The value to type, from 0 to 65,535.
  110. ---
  111. ### `void send_byte(uint8_t number)`
  112. Type out a two digit (8-bit) hexadecimal value.
  113. The format is `[0-9a-f]{2}`, eg. `00` through `ff`.
  114. #### Arguments
  115. - `uint8_t number`
  116. The value to type, from 0 to 255.
  117. ---
  118. ### `void send_nibble(uint8_t number)`
  119. Type out a single hexadecimal digit.
  120. The format is `[0-9a-f]{1}`, eg. `0` through `f`.
  121. #### Arguments
  122. - `uint8_t number`
  123. The value to type, from 0 to 15.
  124. ---
  125. ### `void tap_random_base64(void)`
  126. Type a pseudorandom character from the set `A-Z`, `a-z`, `0-9`, `+` and `/`.
  127. ---
  128. ### `SEND_STRING(string)`
  129. Shortcut macro for `send_string_with_delay_P(PSTR(string), 0)`.
  130. On ARM devices, this define evaluates to `send_string_with_delay(string, 0)`.
  131. ---
  132. ### `SEND_STRING_DELAY(string, interval)`
  133. Shortcut macro for `send_string_with_delay_P(PSTR(string), interval)`.
  134. On ARM devices, this define evaluates to `send_string_with_delay(string, interval)`.