zmk
zmk copied to clipboard
feat(behaviors): Add a send string behavior
This adds the following:
- A character map driver API, which maps Unicode code points to behavior bindings.
- A zmk,character-map driver which implements this API. This driver is designed for ROM efficiency, and it sends every value defined in the map to one behavior and passes any code point not in the map through to another. (A more flexible implementation that allows for a unique behavior binding per character could be added later if necessary.)
- A zmk,send-string behavior, which users can define and bind to their keymaps to send strings.
- A zmk_send_string() function, which queues the necessary behaviors to type a UTF-8 string. This is separated from the send string behavior since it could be used for other features such as Unicode key sequences, behaviors that print dynamic messages, etc.
I will do a second pass later but the docs look great, thank you for the effort you put into it! One suggestion I'd have is to put a pointer in the macros page pointing to this behavior for string sending purposes, similar to the pointer we have for modifier functions.
I've been waiting for this function. If there is a printf-style format function, I would be more than happy. Once I read the zephyr's code related to printf, It's difficult to understand to me.
One suggestion I'd have is to put a pointer in the macros page pointing to this behavior for string sending purposes, similar to the pointer we have for modifier functions.
Good idea. I'll add that.
I've been waiting for this function. If there is a printf-style format function, I would be more than happy. Once I read the zephyr's code related to printf, It's difficult to understand to me.
You could use the zmk_send_string()
function with printf by printing to a string buffer and then sending that to the function, for example:
struct zmk_send_string_config config = {
.character_map = DEVICE_DT_GET(DT_CHOSEN(zmk_character_map)),
.wait_ms = CONFIG_ZMK_SEND_STRING_DEFAULT_WAIT_MS,
.tap_ms = CONFIG_ZMK_SEND_STRING_DEFAULT_TAP_MS,
};
char string[32];
snprintf(string, sizeof(string), "Battery level is %u%%", zmk_battery_state_of_charge());
zmk_send_string(&config, position, string);
I added some macros for creating the config structs, so the code example above can now be simplified to
ZMK_BUILD_ASSERT_CHARACTER_MAP_CHOSEN();
...
char string[32];
snprintf(string, sizeof(string), "Battery level is %u%%", zmk_battery_state_of_charge());
zmk_send_string(&ZMK_SEND_STRING_CONFIG_DEFAULT, position, string);
LGTM from a docs perspective :+1:
pr broken because of this? https://github.com/zmkfirmware/zmk/commit/690bc1bb44b1b62228900906cb308dc6f1a05eb8
Will be great if this gets merged!
Rebased and fixed everything to work with current ZMK.
I've been eagerly waiting for this for almost a year now. Is there any chance we'll get to see this merged soon? Thank you!