diff options
| author | Nick Brassel <nick@tzarc.org> | 2020-02-27 20:38:19 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-27 20:38:19 +1100 |
| commit | 444fd3b1cc07d7f68aa37cbc9e38f2e4ed4d3ea7 (patch) | |
| tree | 9198deb31eb8b79b3416f3806ef5d6b9da340829 | |
| parent | e18be6910493c132fa84be1f21a579fa9b9e12a9 (diff) | |
| download | qmk_firmware-444fd3b1cc07d7f68aa37cbc9e38f2e4ed4d3ea7.tar.gz qmk_firmware-444fd3b1cc07d7f68aa37cbc9e38f2e4ed4d3ea7.zip | |
Add support for delays in send_string. (#8244)
| -rw-r--r-- | docs/feature_macros.md | 20 | ||||
| -rw-r--r-- | quantum/quantum.c | 79 | ||||
| -rw-r--r-- | quantum/send_string_keycodes.h | 10 |
3 files changed, 75 insertions, 34 deletions
diff --git a/docs/feature_macros.md b/docs/feature_macros.md index 7ca945683..99dd564bf 100644 --- a/docs/feature_macros.md +++ b/docs/feature_macros.md | |||
| @@ -107,6 +107,16 @@ Would tap `KC_HOME` - note how the prefix is now `X_`, and not `KC_`. You can al | |||
| 107 | 107 | ||
| 108 | Which would send "VE" followed by a `KC_HOME` tap, and "LO" (spelling "LOVE" if on a newline). | 108 | Which would send "VE" followed by a `KC_HOME` tap, and "LO" (spelling "LOVE" if on a newline). |
| 109 | 109 | ||
| 110 | Delays can be also added to the string: | ||
| 111 | |||
| 112 | * `SS_DELAY(msecs)` will delay for the specified number of milliseconds. | ||
| 113 | |||
| 114 | For example: | ||
| 115 | |||
| 116 | SEND_STRING("VE" SS_DELAY(1000) SS_TAP(X_HOME) "LO"); | ||
| 117 | |||
| 118 | Which would send "VE" followed by a 1-second delay, then a `KC_HOME` tap, and "LO" (spelling "LOVE" if on a newline, but delayed in the middle). | ||
| 119 | |||
| 110 | There's also a couple of mod shortcuts you can use: | 120 | There's also a couple of mod shortcuts you can use: |
| 111 | 121 | ||
| 112 | * `SS_LCTL(string)` | 122 | * `SS_LCTL(string)` |
| @@ -200,11 +210,11 @@ This will clear all mods currently pressed. | |||
| 200 | 210 | ||
| 201 | This will clear all keys besides the mods currently pressed. | 211 | This will clear all keys besides the mods currently pressed. |
| 202 | 212 | ||
| 203 | ## Advanced Example: | 213 | ## Advanced Example: |
| 204 | 214 | ||
| 205 | ### Super ALT↯TAB | 215 | ### Super ALT↯TAB |
| 206 | 216 | ||
| 207 | This macro will register `KC_LALT` and tap `KC_TAB`, then wait for 1000ms. If the key is tapped again, it will send another `KC_TAB`; if there is no tap, `KC_LALT` will be unregistered, thus allowing you to cycle through windows. | 217 | This macro will register `KC_LALT` and tap `KC_TAB`, then wait for 1000ms. If the key is tapped again, it will send another `KC_TAB`; if there is no tap, `KC_LALT` will be unregistered, thus allowing you to cycle through windows. |
| 208 | 218 | ||
| 209 | ```c | 219 | ```c |
| 210 | bool is_alt_tab_active = false; # ADD this near the begining of keymap.c | 220 | bool is_alt_tab_active = false; # ADD this near the begining of keymap.c |
| @@ -221,7 +231,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 221 | if (!is_alt_tab_active) { | 231 | if (!is_alt_tab_active) { |
| 222 | is_alt_tab_active = true; | 232 | is_alt_tab_active = true; |
| 223 | register_code(KC_LALT); | 233 | register_code(KC_LALT); |
| 224 | } | 234 | } |
| 225 | alt_tab_timer = timer_read(); | 235 | alt_tab_timer = timer_read(); |
| 226 | register_code(KC_TAB); | 236 | register_code(KC_TAB); |
| 227 | } else { | 237 | } else { |
| @@ -232,7 +242,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 232 | return true; | 242 | return true; |
| 233 | } | 243 | } |
| 234 | 244 | ||
| 235 | void matrix_scan_user(void) { # The very important timer. | 245 | void matrix_scan_user(void) { # The very important timer. |
| 236 | if (is_alt_tab_active) { | 246 | if (is_alt_tab_active) { |
| 237 | if (timer_elapsed(alt_tab_timer) > 1000) { | 247 | if (timer_elapsed(alt_tab_timer) > 1000) { |
| 238 | unregister_code(KC_LALT); | 248 | unregister_code(KC_LALT); |
| @@ -321,7 +331,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 321 | ``` | 331 | ``` |
| 322 | 332 | ||
| 323 | 333 | ||
| 324 | ## Advanced Example: | 334 | ## Advanced Example: |
| 325 | 335 | ||
| 326 | ### Single-Key Copy/Paste | 336 | ### Single-Key Copy/Paste |
| 327 | 337 | ||
diff --git a/quantum/quantum.c b/quantum/quantum.c index 52062bb17..1b5ce3292 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #include <ctype.h> | ||
| 17 | #include "quantum.h" | 18 | #include "quantum.h" |
| 18 | 19 | ||
| 19 | #ifdef PROTOCOL_LUFA | 20 | #ifdef PROTOCOL_LUFA |
| @@ -374,19 +375,32 @@ void send_string_with_delay(const char *str, uint8_t interval) { | |||
| 374 | while (1) { | 375 | while (1) { |
| 375 | char ascii_code = *str; | 376 | char ascii_code = *str; |
| 376 | if (!ascii_code) break; | 377 | if (!ascii_code) break; |
| 377 | if (ascii_code == SS_TAP_CODE) { | 378 | if (ascii_code == SS_QMK_PREFIX) { |
| 378 | // tap | 379 | ascii_code = *(++str); |
| 379 | uint8_t keycode = *(++str); | 380 | if (ascii_code == SS_TAP_CODE) { |
| 380 | register_code(keycode); | 381 | // tap |
| 381 | unregister_code(keycode); | 382 | uint8_t keycode = *(++str); |
| 382 | } else if (ascii_code == SS_DOWN_CODE) { | 383 | register_code(keycode); |
| 383 | // down | 384 | unregister_code(keycode); |
| 384 | uint8_t keycode = *(++str); | 385 | } else if (ascii_code == SS_DOWN_CODE) { |
| 385 | register_code(keycode); | 386 | // down |
| 386 | } else if (ascii_code == SS_UP_CODE) { | 387 | uint8_t keycode = *(++str); |
| 387 | // up | 388 | register_code(keycode); |
| 388 | uint8_t keycode = *(++str); | 389 | } else if (ascii_code == SS_UP_CODE) { |
| 389 | unregister_code(keycode); | 390 | // up |
| 391 | uint8_t keycode = *(++str); | ||
| 392 | unregister_code(keycode); | ||
| 393 | } else if (ascii_code == SS_DELAY_CODE) { | ||
| 394 | // delay | ||
| 395 | int ms = 0; | ||
| 396 | uint8_t keycode = *(++str); | ||
| 397 | while (isdigit(keycode)) { | ||
| 398 | ms *= 10; | ||
| 399 | ms += keycode - '0'; | ||
| 400 | keycode = *(++str); | ||
| 401 | } | ||
| 402 | while (ms--) wait_ms(1); | ||
| 403 | } | ||
| 390 | } else { | 404 | } else { |
| 391 | send_char(ascii_code); | 405 | send_char(ascii_code); |
| 392 | } | 406 | } |
| @@ -403,19 +417,32 @@ void send_string_with_delay_P(const char *str, uint8_t interval) { | |||
| 403 | while (1) { | 417 | while (1) { |
| 404 | char ascii_code = pgm_read_byte(str); | 418 | char ascii_code = pgm_read_byte(str); |
| 405 | if (!ascii_code) break; | 419 | if (!ascii_code) break; |
| 406 | if (ascii_code == SS_TAP_CODE) { | 420 | if (ascii_code == SS_QMK_PREFIX) { |
| 407 | // tap | 421 | ascii_code = pgm_read_byte(++str); |
| 408 | uint8_t keycode = pgm_read_byte(++str); | 422 | if (ascii_code == SS_TAP_CODE) { |
| 409 | register_code(keycode); | 423 | // tap |
| 410 | unregister_code(keycode); | 424 | uint8_t keycode = pgm_read_byte(++str); |
| 411 | } else if (ascii_code == SS_DOWN_CODE) { | 425 | register_code(keycode); |
| 412 | // down | 426 | unregister_code(keycode); |
| 413 | uint8_t keycode = pgm_read_byte(++str); | 427 | } else if (ascii_code == SS_DOWN_CODE) { |
| 414 | register_code(keycode); | 428 | // down |
| 415 | } else if (ascii_code == SS_UP_CODE) { | 429 | uint8_t keycode = pgm_read_byte(++str); |
| 416 | // up | 430 | register_code(keycode); |
| 417 | uint8_t keycode = pgm_read_byte(++str); | 431 | } else if (ascii_code == SS_UP_CODE) { |
| 418 | unregister_code(keycode); | 432 | // up |
| 433 | uint8_t keycode = pgm_read_byte(++str); | ||
| 434 | unregister_code(keycode); | ||
| 435 | } else if (ascii_code == SS_DELAY_CODE) { | ||
| 436 | // delay | ||
| 437 | int ms = 0; | ||
| 438 | uint8_t keycode = pgm_read_byte(++str); | ||
| 439 | while (isdigit(keycode)) { | ||
| 440 | ms *= 10; | ||
| 441 | ms += keycode - '0'; | ||
| 442 | keycode = pgm_read_byte(++str); | ||
| 443 | } | ||
| 444 | while (ms--) wait_ms(1); | ||
| 445 | } | ||
| 419 | } else { | 446 | } else { |
| 420 | send_char(ascii_code); | 447 | send_char(ascii_code); |
| 421 | } | 448 | } |
diff --git a/quantum/send_string_keycodes.h b/quantum/send_string_keycodes.h index b4a50f84d..86dc8bf00 100644 --- a/quantum/send_string_keycodes.h +++ b/quantum/send_string_keycodes.h | |||
| @@ -382,13 +382,17 @@ | |||
| 382 | #define ADD_SLASH_X(y) STRINGIZE(\x##y) | 382 | #define ADD_SLASH_X(y) STRINGIZE(\x##y) |
| 383 | #define SYMBOL_STR(x) ADD_SLASH_X(x) | 383 | #define SYMBOL_STR(x) ADD_SLASH_X(x) |
| 384 | 384 | ||
| 385 | #define SS_QMK_PREFIX 1 | ||
| 386 | |||
| 385 | #define SS_TAP_CODE 1 | 387 | #define SS_TAP_CODE 1 |
| 386 | #define SS_DOWN_CODE 2 | 388 | #define SS_DOWN_CODE 2 |
| 387 | #define SS_UP_CODE 3 | 389 | #define SS_UP_CODE 3 |
| 390 | #define SS_DELAY_CODE 4 | ||
| 388 | 391 | ||
| 389 | #define SS_TAP(keycode) "\1" SYMBOL_STR(keycode) | 392 | #define SS_TAP(keycode) "\1\1" SYMBOL_STR(keycode) |
| 390 | #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode) | 393 | #define SS_DOWN(keycode) "\1\2" SYMBOL_STR(keycode) |
| 391 | #define SS_UP(keycode) "\3" SYMBOL_STR(keycode) | 394 | #define SS_UP(keycode) "\1\3" SYMBOL_STR(keycode) |
| 395 | #define SS_DELAY(msecs) "\1\4" STRINGIZE(msecs) "|" | ||
| 392 | 396 | ||
| 393 | // `string` arguments must not be parenthesized | 397 | // `string` arguments must not be parenthesized |
| 394 | #define SS_LCTL(string) SS_DOWN(X_LCTL) string SS_UP(X_LCTL) | 398 | #define SS_LCTL(string) SS_DOWN(X_LCTL) string SS_UP(X_LCTL) |
