send_string.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. * \file
  18. *
  19. * \defgroup send_string Send String API
  20. *
  21. * \brief These functions allow you to create macros by typing out sequences of keystrokes.
  22. * \{
  23. */
  24. #include <stdint.h>
  25. #include "progmem.h"
  26. #include "send_string_keycodes.h"
  27. // Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
  28. extern const uint8_t ascii_to_shift_lut[16];
  29. extern const uint8_t ascii_to_altgr_lut[16];
  30. extern const uint8_t ascii_to_dead_lut[16];
  31. extern const uint8_t ascii_to_keycode_lut[128];
  32. // clang-format off
  33. #define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
  34. ( ((a) ? 1 : 0) << 0 \
  35. | ((b) ? 1 : 0) << 1 \
  36. | ((c) ? 1 : 0) << 2 \
  37. | ((d) ? 1 : 0) << 3 \
  38. | ((e) ? 1 : 0) << 4 \
  39. | ((f) ? 1 : 0) << 5 \
  40. | ((g) ? 1 : 0) << 6 \
  41. | ((h) ? 1 : 0) << 7 )
  42. // clang-format on
  43. /**
  44. * \brief Type out a string of ASCII characters.
  45. *
  46. * This function simply calls `send_string_with_delay(string, 0)`.
  47. *
  48. * Most keycodes from the basic keycode range are also supported by way of a special sequence - see `send_string_keycodes.h`.
  49. *
  50. * \param string The string to type out.
  51. */
  52. void send_string(const char *string);
  53. /**
  54. * \brief Type out a string of ASCII characters, with a delay between each character.
  55. *
  56. * \param string The string to type out.
  57. * \param interval The amount of time, in milliseconds, to wait before typing the next character.
  58. */
  59. void send_string_with_delay(const char *string, uint8_t interval);
  60. /**
  61. * \brief Type out an ASCII character.
  62. *
  63. * \param ascii_code The character to type.
  64. */
  65. void send_char(char ascii_code);
  66. /**
  67. * \brief Type out an eight digit (unsigned 32-bit) hexadecimal value.
  68. *
  69. * The format is `[0-9a-f]{8}`, eg. `00000000` through `ffffffff`.
  70. *
  71. * \param number The value to type, from 0 to 4,294,967,295.
  72. */
  73. void send_dword(uint32_t number);
  74. /**
  75. * \brief Type out a four digit (unsigned 16-bit) hexadecimal value.
  76. *
  77. * The format is `[0-9a-f]{4}`, eg. `0000` through `ffff`.
  78. *
  79. * \param number The value to type, from 0 to 65,535.
  80. */
  81. void send_word(uint16_t number);
  82. /**
  83. * \brief Type out a two digit (8-bit) hexadecimal value.
  84. *
  85. * The format is `[0-9a-f]{2}`, eg. `00` through `ff`.
  86. *
  87. * \param number The value to type, from 0 to 255.
  88. */
  89. void send_byte(uint8_t number);
  90. /**
  91. * \brief Type out a single hexadecimal digit.
  92. *
  93. * The format is `[0-9a-f]{1}`, eg. `0` through `f`.
  94. *
  95. * \param number The value to type, from 0 to 15.
  96. */
  97. void send_nibble(uint8_t number);
  98. /**
  99. * \brief Type a pseudorandom character from the set `A-Z`, `a-z`, `0-9`, `+` and `/`.
  100. */
  101. void tap_random_base64(void);
  102. #if defined(__AVR__) || defined(__DOXYGEN__)
  103. /**
  104. * \brief Type out a PROGMEM string of ASCII characters.
  105. *
  106. * On ARM devices, this function is simply an alias for send_string_with_delay(string, 0).
  107. *
  108. * \param string The string to type out.
  109. */
  110. void send_string_P(const char *string);
  111. /**
  112. * \brief Type out a PROGMEM string of ASCII characters, with a delay between each character.
  113. *
  114. * On ARM devices, this function is simply an alias for send_string_with_delay(string, interval).
  115. *
  116. * \param string The string to type out.
  117. * \param interval The amount of time, in milliseconds, to wait before typing the next character.
  118. */
  119. void send_string_with_delay_P(const char *string, uint8_t interval);
  120. #else
  121. # define send_string_P(string) send_string_with_delay(string, 0)
  122. # define send_string_with_delay_P(string, interval) send_string_with_delay(string, interval)
  123. #endif
  124. /**
  125. * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), 0).
  126. *
  127. * On ARM devices, this define evaluates to send_string_with_delay(string, 0).
  128. */
  129. #define SEND_STRING(string) send_string_with_delay_P(PSTR(string), 0)
  130. /**
  131. * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), interval).
  132. *
  133. * On ARM devices, this define evaluates to send_string_with_delay(string, interval).
  134. */
  135. #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
  136. /** \} */