💿🐜 Antkeeper source code https://antkeeper.com
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.

88 lines
2.7 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_INPUT_KEYBOARD_HPP
  20. #define ANTKEEPER_INPUT_KEYBOARD_HPP
  21. #include "input/device.hpp"
  22. #include "input/input-events.hpp"
  23. #include "input/scancode.hpp"
  24. #include "input/modifier-key.hpp"
  25. #include "event/publisher.hpp"
  26. namespace input {
  27. /**
  28. * A virtual keyboard which generates keyboard-related input events.
  29. */
  30. class keyboard: public device
  31. {
  32. public:
  33. /**
  34. * Constructs a keyboard input device.
  35. */
  36. keyboard() = default;
  37. /// Destructs a keyboard input device.
  38. virtual ~keyboard() = default;
  39. /**
  40. * Simulates a key press.
  41. *
  42. * @param scancode Scancode of the key to press.
  43. * @param repeat `true` if the key press is from a key repeat, `false` otherwise.
  44. * @param modifiers Bit mask containing the active modifier keys.
  45. */
  46. void press(scancode scancode, bool repeat = false, std::uint16_t modifiers = modifier_key::none);
  47. /**
  48. * Simulates a key release.
  49. *
  50. * @param scancode Scancode of the key to release.
  51. * @param repeat `true` if the key release is from a key repeat, `false` otherwise.
  52. * @param modifiers Bit mask containing the active modifier keys.
  53. */
  54. void release(scancode scancode, bool repeat = false, std::uint16_t modifiers = modifier_key::none);
  55. /// Returns the channel through which key pressed events are published.
  56. [[nodiscard]] inline ::event::channel<key_pressed_event>& get_key_pressed_channel() noexcept
  57. {
  58. return key_pressed_publisher.channel();
  59. }
  60. /// Returns the channel through which key released events are published.
  61. [[nodiscard]] inline ::event::channel<key_released_event>& get_key_released_channel() noexcept
  62. {
  63. return key_released_publisher.channel();
  64. }
  65. /// Returns device_type::keyboard.
  66. [[nodiscard]] inline virtual constexpr device_type get_device_type() const noexcept
  67. {
  68. return device_type::keyboard;
  69. }
  70. private:
  71. ::event::publisher<key_pressed_event> key_pressed_publisher;
  72. ::event::publisher<key_released_event> key_released_publisher;
  73. };
  74. } // namespace input
  75. #endif // ANTKEEPER_INPUT_KEYBOARD_HPP