import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js"; const __pageData = JSON.parse('{"title":"Send String","description":"","frontmatter":{},"headers":[],"relativePath":"features/send_string.md","filePath":"features/send_string.md","lastUpdated":null}'); const _sfc_main = { name: "features/send_string.md" }; const _hoisted_1 = /* @__PURE__ */ createStaticVNode('

Send String

The Send String API is part of QMK's macro system. It allows for sequences of keystrokes to be sent automatically.

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).

TIP

Unicode characters are not supported with this API -- see the Unicode feature instead.

Usage

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:

make
SEND_STRING_ENABLE = yes

Basic Configuration

Add the following to your config.h:

DefineDefaultDescription
SENDSTRING_BELLNot definedIf the Audio feature is enabled, the \\a character (ASCII BEL) will beep the speaker.
BELL_SOUNDTERMINAL_SOUNDThe song to play when the \\a character is encountered. By default, this is an eighth note of C5.

Keycodes

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 are supported (as these are the only ones that will actually be sent to the host), but with an X_ prefix instead of KC_.

MacroDescription
SS_TAP(x)Send a keydown, then keyup, event for the given Send String keycode
SS_DOWN(x)Send a keydown event for the given Send String keycode
SS_UP(x)Send a keyup event for the given Send String keycode
SS_DELAY(ms)Wait for ms milliseconds

The following characters are also mapped to their respective keycodes for convenience:

CharacterHexASCIIKeycode
\\b\\x08BSKC_BACKSPACE
\\e\\x09ESCKC_ESCAPE
\\n\\x0ALFKC_ENTER
\\t\\x1BTABKC_TAB
\\x7FDELKC_DELETE

Language Support

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.

Examples

Hello World

A simple custom keycode which types out "Hello, world!" and the Enter key when pressed.

Add the following to your keymap.c:

c
bool process_record_user(uint16_t keycode, keyrecord_t *record) {\n    switch (keycode) {\n        case SS_HELLO:\n            if (record->event.pressed) {\n                SEND_STRING("Hello, world!\\n");\n            }\n            return false;\n    }\n\n    return true;\n}

Keycode Injection

This example types out opening and closing curly braces, then taps the left arrow key to move the cursor between the two.

c
SEND_STRING("{}" SS_TAP(X_LEFT));

This example types Ctrl+A, then Ctrl+C, without releasing Ctrl.

c
SEND_STRING(SS_LCTL("ac"));

API

void send_string(const char *string)

Type out a string of ASCII characters.

This function simply calls send_string_with_delay(string, 0).

Arguments


void send_string_with_delay(const char *string, uint8_t interval)

Type out a string of ASCII characters, with a delay between each character.

Arguments


void send_string_P(const char *string)

Type out a PROGMEM string of ASCII characters.

On ARM devices, this function is simply an alias for send_string_with_delay(string, 0).

Arguments


void send_string_with_delay_P(const char *string, uint8_t interval)

Type out a PROGMEM string of ASCII characters, with a delay between each character.

On ARM devices, this function is simply an alias for send_string_with_delay(string, interval).

Arguments


void send_char(char ascii_code)

Type out an ASCII character.

Arguments


void send_dword(uint32_t number)

Type out an eight digit (unsigned 32-bit) hexadecimal value.

The format is [0-9a-f]{8}, eg. 00000000 through ffffffff.

Arguments


void send_word(uint16_t number)

Type out a four digit (unsigned 16-bit) hexadecimal value.

The format is [0-9a-f]{4}, eg. 0000 through ffff.

Arguments


void send_byte(uint8_t number)

Type out a two digit (8-bit) hexadecimal value.

The format is [0-9a-f]{2}, eg. 00 through ff.

Arguments


void send_nibble(uint8_t number)

Type out a single hexadecimal digit.

The format is [0-9a-f]{1}, eg. 0 through f.

Arguments


void tap_random_base64(void)

Type a pseudorandom character from the set A-Z, a-z, 0-9, + and /.


SEND_STRING(string)

Shortcut macro for send_string_with_delay_P(PSTR(string), 0).

On ARM devices, this define evaluates to send_string_with_delay(string, 0).


SEND_STRING_DELAY(string, interval)

Shortcut macro for send_string_with_delay_P(PSTR(string), interval).

On ARM devices, this define evaluates to send_string_with_delay(string, interval).

', 90); const _hoisted_91 = [ _hoisted_1 ]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("div", null, _hoisted_91); } const send_string = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { __pageData, send_string as default };