send_string.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright 2021
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * \defgroup send_string
  18. *
  19. * Send String API. These functions allow you to create macros by typing out sequences of keystrokes.
  20. * \{
  21. */
  22. #include <stdint.h>
  23. #include "progmem.h"
  24. #include "send_string_keycodes.h"
  25. // Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
  26. extern const uint8_t ascii_to_shift_lut[16];
  27. extern const uint8_t ascii_to_altgr_lut[16];
  28. extern const uint8_t ascii_to_dead_lut[16];
  29. extern const uint8_t ascii_to_keycode_lut[128];
  30. // clang-format off
  31. #define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
  32. ( ((a) ? 1 : 0) << 0 \
  33. | ((b) ? 1 : 0) << 1 \
  34. | ((c) ? 1 : 0) << 2 \
  35. | ((d) ? 1 : 0) << 3 \
  36. | ((e) ? 1 : 0) << 4 \
  37. | ((f) ? 1 : 0) << 5 \
  38. | ((g) ? 1 : 0) << 6 \
  39. | ((h) ? 1 : 0) << 7 )
  40. // clang-format on
  41. /**
  42. * \brief Type out a string of ASCII characters.
  43. *
  44. * This function simply calls `send_string_with_delay(string, 0)`.
  45. *
  46. * Most keycodes from the basic keycode range are also supported by way of a special sequence - see `send_string_keycodes.h`.
  47. *
  48. * \param string The string to type out.
  49. */
  50. void send_string(const char *string);
  51. /**
  52. * \brief Type out a string of ASCII characters, with a delay between each character.
  53. *
  54. * \param string The string to type out.
  55. * \param interval The amount of time, in milliseconds, to wait before typing the next character.
  56. */
  57. void send_string_with_delay(const char *string, uint8_t interval);
  58. /**
  59. * \brief Type out an ASCII character.
  60. *
  61. * \param ascii_code The character to type.
  62. */
  63. void send_char(char ascii_code);
  64. /**
  65. * \brief Type out an eight digit (unsigned 32-bit) hexadecimal value.
  66. *
  67. * The format is `[0-9a-f]{8}`, eg. `00000000` through `ffffffff`.
  68. *
  69. * \param number The value to type, from 0 to 4,294,967,295.
  70. */
  71. void send_dword(uint32_t number);
  72. /**
  73. * \brief Type out a four digit (unsigned 16-bit) hexadecimal value.
  74. *
  75. * The format is `[0-9a-f]{4}`, eg. `0000` through `ffff`.
  76. *
  77. * \param number The value to type, from 0 to 65,535.
  78. */
  79. void send_word(uint16_t number);
  80. /**
  81. * \brief Type out a two digit (8-bit) hexadecimal value.
  82. *
  83. * The format is `[0-9a-f]{2}`, eg. `00` through `ff`.
  84. *
  85. * \param number The value to type, from 0 to 255.
  86. */
  87. void send_byte(uint8_t number);
  88. /**
  89. * \brief Type out a single hexadecimal digit.
  90. *
  91. * The format is `[0-9a-f]{1}`, eg. `0` through `f`.
  92. *
  93. * \param number The value to type, from 0 to 15.
  94. */
  95. void send_nibble(uint8_t number);
  96. /**
  97. * \brief Type a pseudorandom character from the set `A-Z`, `a-z`, `0-9`, `+` and `/`.
  98. */
  99. void tap_random_base64(void);
  100. #if defined(__AVR__) || defined(__DOXYGEN__)
  101. /**
  102. * \brief Type out a PROGMEM string of ASCII characters.
  103. *
  104. * On ARM devices, this function is simply an alias for send_string_with_delay(string, 0).
  105. *
  106. * \param string The string to type out.
  107. */
  108. void send_string_P(const char *string);
  109. /**
  110. * \brief Type out a PROGMEM string of ASCII characters, with a delay between each character.
  111. *
  112. * On ARM devices, this function is simply an alias for send_string_with_delay(string, interval).
  113. *
  114. * \param string The string to type out.
  115. * \param interval The amount of time, in milliseconds, to wait before typing the next character.
  116. */
  117. void send_string_with_delay_P(const char *string, uint8_t interval);
  118. #else
  119. # define send_string_P(string) send_string_with_delay(string, 0)
  120. # define send_string_with_delay_P(string, interval) send_string_with_delay(string, interval)
  121. #endif
  122. /**
  123. * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), 0).
  124. *
  125. * On ARM devices, this define evaluates to send_string_with_delay(string, 0).
  126. */
  127. #define SEND_STRING(string) send_string_with_delay_P(PSTR(string), 0)
  128. /**
  129. * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), interval).
  130. *
  131. * On ARM devices, this define evaluates to send_string_with_delay(string, interval).
  132. */
  133. #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
  134. /** \} */