FifeGUI 0.2.0
A C++ GUI library designed for games.
keyinput.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_KEYINPUT_HPP_
6#define INCLUDE_FIFECHAN_KEYINPUT_HPP_
7
8#include <cstdint>
9
10#include "fifechan/key.hpp"
11#include "fifechan/platform.hpp"
12
13namespace fcn
14{
27 class FIFEGUI_API KeyInput
28 {
29 public:
35 enum class Type : std::uint8_t
36 {
37 Pressed = 0,
38 Released
39 };
40
44 KeyInput() = default;
45
52 KeyInput(Key const & key, Type type);
53
60 void setType(Type type);
61
68 Type getType() const;
69
76 void setKey(Key const & key);
77
84 Key const & getKey() const;
85
93 bool isShiftPressed() const;
94
102 void setShiftPressed(bool pressed);
103
111 bool isControlPressed() const;
112
120 void setControlPressed(bool pressed);
121
129 bool isAltPressed() const;
130
139 void setAltPressed(bool pressed);
140
148 bool isMetaPressed() const;
149
158 void setMetaPressed(bool pressed);
159
167 bool isNumericPad() const;
168
176 void setNumericPad(bool numpad);
177
178 protected:
183
187 Type mType{Type::Released};
188
193 bool mShiftPressed{false};
194
199 bool mControlPressed{false};
200
205 bool mAltPressed{false};
206
211 bool mMetaPressed{false};
212
217 bool mNumericPad{false};
218 };
219} // namespace fcn
220
221#endif // INCLUDE_FIFECHAN_KEYINPUT_HPP_
bool isAltPressed() const
Checks if alt is pressed.
Definition keyinput.cpp:53
void setType(Type type)
Sets the type of the key input.
Definition keyinput.cpp:13
Type
Key input event types.
Definition keyinput.hpp:36
bool mMetaPressed
True if meta was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:211
bool isNumericPad() const
Checks if the key was pressed at the numeric pad.
Definition keyinput.cpp:73
Type getType() const
Gets the type of the key input.
Definition keyinput.cpp:18
bool mControlPressed
True if control was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:199
bool isControlPressed() const
Checks if control is pressed.
Definition keyinput.cpp:43
KeyInput()=default
Constructor.
void setAltPressed(bool pressed)
Sets the alt to be pressed at the same time as the key, or not.
Definition keyinput.cpp:58
void setNumericPad(bool numpad)
Sets the key to be pressed at the numeric pad.
Definition keyinput.cpp:78
void setControlPressed(bool pressed)
Sets control to be pressed at the same time as the key, or not.
Definition keyinput.cpp:48
void setKey(Key const &key)
Sets the key of the key input.
Definition keyinput.cpp:23
bool mNumericPad
True if the numeric pad was used when the key was pressed, false otherwise.
Definition keyinput.hpp:217
bool mShiftPressed
True if shift was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:193
Key mKey
Holds the key of the key input.
Definition keyinput.hpp:182
bool isMetaPressed() const
Checks if meta is pressed.
Definition keyinput.cpp:63
void setMetaPressed(bool pressed)
Sets meta to be pressed at the same time as the key, or not.
Definition keyinput.cpp:68
void setShiftPressed(bool pressed)
Sets shift to be pressed at the same time as the key, or not.
Definition keyinput.cpp:38
Type mType
Holds the type of the key input.
Definition keyinput.hpp:187
Key const & getKey() const
Gets the key of the key input.
Definition keyinput.cpp:28
bool isShiftPressed() const
Checks if shift is pressed.
Definition keyinput.cpp:33
bool mAltPressed
True if alt was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:205
Represents a keyboard key or character code.
Definition key.hpp:20