You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
5.1 KiB

  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, TAP_CODE_DELAY)`.
  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. Note this can be set to 0 to ensure no delay, regardless of what TAP_CODE_DELAY is set to.
  58. */
  59. void send_string_with_delay(const char *string, uint8_t interval);
  60. /**
  61. * \brief Type out an ASCII character.
  62. *
  63. * This function simply calls `send_char_with_delay(string, TAP_CODE_DELAY)`.
  64. *
  65. * \param ascii_code The character to type.
  66. */
  67. void send_char(char ascii_code);
  68. /**
  69. * \brief Type out an ASCII character, with a delay between any modifiers.
  70. *
  71. * \param ascii_code The character to type.
  72. * \param interval The amount of time, in milliseconds, to wait in between key presses. Note this can be set to 0 to ensure no delay, regardless of what TAP_CODE_DELAY is set to.
  73. */
  74. void send_char_with_delay(char ascii_code, uint8_t interval);
  75. /**
  76. * \brief Type out an eight digit (unsigned 32-bit) hexadecimal value.
  77. *
  78. * The format is `[0-9a-f]{8}`, eg. `00000000` through `ffffffff`.
  79. *
  80. * \param number The value to type, from 0 to 4,294,967,295.
  81. */
  82. void send_dword(uint32_t number);
  83. /**
  84. * \brief Type out a four digit (unsigned 16-bit) hexadecimal value.
  85. *
  86. * The format is `[0-9a-f]{4}`, eg. `0000` through `ffff`.
  87. *
  88. * \param number The value to type, from 0 to 65,535.
  89. */
  90. void send_word(uint16_t number);
  91. /**
  92. * \brief Type out a two digit (8-bit) hexadecimal value.
  93. *
  94. * The format is `[0-9a-f]{2}`, eg. `00` through `ff`.
  95. *
  96. * \param number The value to type, from 0 to 255.
  97. */
  98. void send_byte(uint8_t number);
  99. /**
  100. * \brief Type out a single hexadecimal digit.
  101. *
  102. * The format is `[0-9a-f]{1}`, eg. `0` through `f`.
  103. *
  104. * \param number The value to type, from 0 to 15.
  105. */
  106. void send_nibble(uint8_t number);
  107. /**
  108. * \brief Type a pseudorandom character from the set `A-Z`, `a-z`, `0-9`, `+` and `/`.
  109. */
  110. void tap_random_base64(void);
  111. #if defined(__AVR__) || defined(__DOXYGEN__)
  112. /**
  113. * \brief Type out a PROGMEM string of ASCII characters.
  114. *
  115. * On ARM devices, this function is simply an alias for send_string_with_delay(string, 0).
  116. *
  117. * \param string The string to type out.
  118. */
  119. void send_string_P(const char *string);
  120. /**
  121. * \brief Type out a PROGMEM string of ASCII characters, with a delay between each character.
  122. *
  123. * On ARM devices, this function is simply an alias for send_string_with_delay(string, interval).
  124. *
  125. * \param string The string to type out.
  126. * \param interval The amount of time, in milliseconds, to wait before typing the next character.
  127. */
  128. void send_string_with_delay_P(const char *string, uint8_t interval);
  129. #else
  130. # define send_string_P(string) send_string_with_delay(string, 0)
  131. # define send_string_with_delay_P(string, interval) send_string_with_delay(string, interval)
  132. #endif
  133. /**
  134. * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), 0).
  135. *
  136. * On ARM devices, this define evaluates to send_string_with_delay(string, 0).
  137. */
  138. #define SEND_STRING(string) send_string_with_delay_P(PSTR(string), 0)
  139. /**
  140. * \brief Shortcut macro for send_string_with_delay_P(PSTR(string), interval).
  141. *
  142. * On ARM devices, this define evaluates to send_string_with_delay(string, interval).
  143. */
  144. #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
  145. /** \} */