repeat_key.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2022-2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "action.h"
  18. #include "keyboard.h"
  19. void reset_repeat_key_state(void); /**< Resets repeat key state. */
  20. uint16_t get_last_keycode(void); /**< Keycode of the last key. */
  21. uint8_t get_last_mods(void); /**< Mods active with the last key. */
  22. void set_last_keycode(uint16_t keycode); /**< Sets the last key. */
  23. void set_last_mods(uint8_t mods); /**< Sets the last mods. */
  24. /** @brief Gets the record for the last key. */
  25. keyrecord_t* get_last_record(void);
  26. /** @brief Sets keycode and record info for the last key. */
  27. void set_last_record(uint16_t keycode, keyrecord_t* record);
  28. /**
  29. * @brief Signed count of times the key has been repeated or alternate repeated.
  30. *
  31. * @note The count is nonzero only while a repeated or alternate-repeated key is
  32. * being processed.
  33. *
  34. * When a key is pressed normally, the count is 0. When the Repeat Key is used
  35. * to repeat a key, the count is 1 on the first repeat, 2 on the second repeat,
  36. * and continuing up to 127.
  37. *
  38. * Negative counts are used similarly for alternate repeating. When the
  39. * Alternate Repeat Key is used, the count is -1 on the first alternate repeat,
  40. * -2 on the second, continuing down to -127.
  41. */
  42. int8_t get_repeat_key_count(void);
  43. /**
  44. * @brief Calls `process_record()` on a generated record repeating the last key.
  45. * @param event Event information in the generated record.
  46. */
  47. void repeat_key_invoke(const keyevent_t* event);
  48. #ifndef NO_ALT_REPEAT_KEY
  49. /**
  50. * @brief Keycode to be used for alternate repeating.
  51. *
  52. * Alternate Repeat performs this keycode based on the last eligible pressed key
  53. * and mods, get_last_keycode() and get_last_mods(). For example, when the last
  54. * key was KC_UP, this function returns KC_DOWN. The function returns KC_NO if
  55. * the last key doesn't have a defined alternate.
  56. */
  57. uint16_t get_alt_repeat_key_keycode(void);
  58. /**
  59. * @brief Calls `process_record()` to alternate repeat the last key.
  60. * @param event Event information in the generated record.
  61. */
  62. void alt_repeat_key_invoke(const keyevent_t* event);
  63. /**
  64. * @brief Optional user callback to define additional alternate keys.
  65. *
  66. * When `get_alt_repeat_key_keycode()` is called, it first calls this callback.
  67. * It should return a keycode representing the "alternate" of the given keycode
  68. * and mods. Returning KC_NO defers to the default definitions in
  69. * `get_alt_repeat_key_keycode()`.
  70. */
  71. uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods);
  72. #endif // NO_ALT_REPEAT_KEY