Antkeeper  0.0.1
keyboard.hpp
Go to the documentation of this file.
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 
20 #ifndef ANTKEEPER_INPUT_KEYBOARD_HPP
21 #define ANTKEEPER_INPUT_KEYBOARD_HPP
22 
23 #include <engine/input/device.hpp>
28 
29 namespace input {
30 
34 class keyboard: public device
35 {
36 public:
44  void press(scancode scancode, std::uint16_t modifiers = modifier_key::none, bool repeat = false);
45 
52  void release(scancode scancode, std::uint16_t modifiers = modifier_key::none);
53 
55  [[nodiscard]] inline ::event::channel<key_pressed_event>& get_key_pressed_channel() noexcept
56  {
57  return key_pressed_publisher.channel();
58  }
59 
61  [[nodiscard]] inline ::event::channel<key_released_event>& get_key_released_channel() noexcept
62  {
63  return key_released_publisher.channel();
64  }
65 
67  [[nodiscard]] inline constexpr device_type get_device_type() const noexcept override
68  {
69  return device_type::keyboard;
70  }
71 
72 private:
73  ::event::publisher<key_pressed_event> key_pressed_publisher;
74  ::event::publisher<key_released_event> key_released_publisher;
75 };
76 
77 } // namespace input
78 
79 #endif // ANTKEEPER_INPUT_KEYBOARD_HPP
Publishes messages to subscribers.
Definition: publisher.hpp:36
Abstract base class for virtual devices that generate input events.
Definition: device.hpp:36
A virtual keyboard which generates keyboard-related input events.
Definition: keyboard.hpp:35
::event::channel< key_released_event > & get_key_released_channel() noexcept
Returns the channel through which key released events are published.
Definition: keyboard.hpp:61
void release(scancode scancode, std::uint16_t modifiers=modifier_key::none)
Simulates a key release.
Definition: keyboard.cpp:30
constexpr device_type get_device_type() const noexcept override
Returns device_type::keyboard.
Definition: keyboard.hpp:67
void press(scancode scancode, std::uint16_t modifiers=modifier_key::none, bool repeat=false)
Simulates a key press.
Definition: keyboard.cpp:25
::event::channel< key_pressed_event > & get_key_pressed_channel() noexcept
Returns the channel through which key pressed events are published.
Definition: keyboard.hpp:55
@ none
No modifier key is pressed.
Input devices, events, and mapping.
scancode
Keyboard scancodes.
Definition: scancode.hpp:33
device_type
Input device types.
Definition: device-type.hpp:29
@ keyboard
Keyboard input device.