FifeGUI 0.3.0
A C++ GUI library designed for games.
keyinput.cpp
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// Corresponding header include
6#include "fifechan/keyinput.hpp"
7
8// Standard library includes
9#include <cassert>
10
11// Project headers (subdirs before local)
12#include "fifechan/key.hpp"
13
14namespace fcn
15{
16 KeyInput::KeyInput(Key const & key, Type type) : mKey(key), mType(type)
17 {
18 assert("Key must be valid" && key.getValue() != 0);
19 assert("Type must be valid" && (type == KeyInput::Type::Pressed || type == KeyInput::Type::Released));
20 }
21
23 {
24 assert("Type must be valid" && (type == KeyInput::Type::Pressed || type == KeyInput::Type::Released));
25
26 mType = type;
27 }
28
30 {
31 return mType;
32 }
33
34 void KeyInput::setKey(Key const & key)
35 {
36 assert("Key must be valid" && key.getValue() != 0);
37
38 mKey = key;
39 }
40
41 Key const & KeyInput::getKey() const
42 {
43 return mKey;
44 }
45
47 {
48 return mShiftPressed;
49 }
50
51 void KeyInput::setShiftPressed(bool pressed)
52 {
53 mShiftPressed = pressed;
54 }
55
57 {
58 return mControlPressed;
59 }
60
61 void KeyInput::setControlPressed(bool pressed)
62 {
63 mControlPressed = pressed;
64 }
65
67 {
68 return mAltPressed;
69 }
70
71 void KeyInput::setAltPressed(bool pressed)
72 {
73 mAltPressed = pressed;
74 }
75
77 {
78 return mMetaPressed;
79 }
80
81 void KeyInput::setMetaPressed(bool pressed)
82 {
83 mMetaPressed = pressed;
84 }
85
87 {
88 return mNumericPad;
89 }
90
91 void KeyInput::setNumericPad(bool numpad)
92 {
93 mNumericPad = numpad;
94 }
95} // namespace fcn
bool isAltPressed() const
Checks if alt is pressed.
Definition keyinput.cpp:66
void setType(Type type)
Sets the type of the key input.
Definition keyinput.cpp:22
Type
Key input event types.
Definition keyinput.hpp:40
bool mMetaPressed
True if meta was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:215
bool isNumericPad() const
Checks if the key was pressed at the numeric pad.
Definition keyinput.cpp:86
Type getType() const
Gets the type of the key input.
Definition keyinput.cpp:29
bool mControlPressed
True if control was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:203
bool isControlPressed() const
Checks if control is pressed.
Definition keyinput.cpp:56
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:71
void setNumericPad(bool numpad)
Sets the key to be pressed at the numeric pad.
Definition keyinput.cpp:91
void setControlPressed(bool pressed)
Sets control to be pressed at the same time as the key, or not.
Definition keyinput.cpp:61
void setKey(Key const &key)
Sets the key of the key input.
Definition keyinput.cpp:34
bool mNumericPad
True if the numeric pad was used when the key was pressed, false otherwise.
Definition keyinput.hpp:221
bool mShiftPressed
True if shift was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:197
Key mKey
Holds the key of the key input.
Definition keyinput.hpp:186
bool isMetaPressed() const
Checks if meta is pressed.
Definition keyinput.cpp:76
void setMetaPressed(bool pressed)
Sets meta to be pressed at the same time as the key, or not.
Definition keyinput.cpp:81
void setShiftPressed(bool pressed)
Sets shift to be pressed at the same time as the key, or not.
Definition keyinput.cpp:51
Type mType
Holds the type of the key input.
Definition keyinput.hpp:191
Key const & getKey() const
Gets the key of the key input.
Definition keyinput.cpp:41
bool isShiftPressed() const
Checks if shift is pressed.
Definition keyinput.cpp:46
bool mAltPressed
True if alt was pressed at the same time as the key, false otherwise.
Definition keyinput.hpp:209
Used replacement tokens by configure_file():