repeat_key.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "quantum.h"
  16. uint16_t get_last_keycode(void); /**< Keycode of the last key. */
  17. uint8_t get_last_mods(void); /**< Mods active with the last key. */
  18. void set_last_keycode(uint16_t keycode); /**< Sets the last key. */
  19. void set_last_mods(uint8_t mods); /**< Sets the last mods. */
  20. /** @brief Gets the record for the last key. */
  21. keyrecord_t* get_last_record(void);
  22. /** @brief Sets keycode and record info for the last key. */
  23. void set_last_record(uint16_t keycode, keyrecord_t* record);
  24. /**
  25. * @brief Signed count of times the key has been repeated or alternate repeated.
  26. *
  27. * @note The count is nonzero only while a repeated or alternate-repeated key is
  28. * being processed.
  29. *
  30. * When a key is pressed normally, the count is 0. When the Repeat Key is used
  31. * to repeat a key, the count is 1 on the first repeat, 2 on the second repeat,
  32. * and continuing up to 127.
  33. *
  34. * Negative counts are used similarly for alternate repeating. When the
  35. * Alternate Repeat Key is used, the count is -1 on the first alternate repeat,
  36. * -2 on the second, continuing down to -127.
  37. */
  38. int8_t get_repeat_key_count(void);
  39. /**
  40. * @brief Calls `process_record()` on a generated record repeating the last key.
  41. * @param event Event information in the generated record.
  42. */
  43. void repeat_key_invoke(const keyevent_t* event);
  44. #ifndef NO_ALT_REPEAT_KEY
  45. /**
  46. * @brief Keycode to be used for alternate repeating.
  47. *
  48. * Alternate Repeat performs this keycode based on the last eligible pressed key
  49. * and mods, get_last_keycode() and get_last_mods(). For example, when the last
  50. * key was KC_UP, this function returns KC_DOWN. The function returns KC_NO if
  51. * the last key doesn't have a defined alternate.
  52. */
  53. uint16_t get_alt_repeat_key_keycode(void);
  54. /**
  55. * @brief Calls `process_record()` to alternate repeat the last key.
  56. * @param event Event information in the generated record.
  57. */
  58. void alt_repeat_key_invoke(const keyevent_t* event);
  59. /**
  60. * @brief Optional user callback to define additional alternate keys.
  61. *
  62. * When `get_alt_repeat_key_keycode()` is called, it first calls this callback.
  63. * It should return a keycode representing the "alternate" of the given keycode
  64. * and mods. Returning KC_NO defers to the default definitions in
  65. * `get_alt_repeat_key_keycode()`.
  66. */
  67. uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods);
  68. #endif // NO_ALT_REPEAT_KEY