ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::integration::event::Keyboard Class Reference

Current Keyboard state. More...

#include <Keyboard.hpp>

Inheritance diagram for ecstasy::integration::event::Keyboard:
Collaboration diagram for ecstasy::integration::event::Keyboard:

Public Types

enum class  Key {
  Unknown = -1 , A , B , C ,
  D , E , F , G ,
  H , I , J , K ,
  L , M , N , O ,
  P , Q , R , S ,
  T , U , V , W ,
  X , Y , Z , Num0 ,
  Num1 , Num2 , Num3 , Num4 ,
  Num5 , Num6 , Num7 , Num8 ,
  Num9 , Escape , LControl , LShift ,
  LAlt , LSystem , RControl , RShift ,
  RAlt , RSystem , Menu , LBracket ,
  RBracket , Semicolon , Comma , Period ,
  Quote , Slash , Backslash , Tilde ,
  Equal , Hyphen , Space , Enter ,
  Backspace , Tab , PageUp , PageDown ,
  End , Home , Insert , Delete ,
  Add , Subtract , Multiply , Divide ,
  Left , Right , Up , Down ,
  Numpad0 , Numpad1 , Numpad2 , Numpad3 ,
  Numpad4 , Numpad5 , Numpad6 , Numpad7 ,
  Numpad8 , Numpad9 , F1 , F2 ,
  F3 , F4 , F5 , F6 ,
  F7 , F8 , F9 , F10 ,
  F11 , F12 , F13 , F14 ,
  F15 , Pause , Count
}
 Keyboard keys. More...
 

Public Member Functions

 Keyboard () noexcept
 Construct a new Keyboard resource.
 
virtual ~Keyboard () noexcept=default
 Destroy the Keyboard.
 
constexpr bool isKeyDown (Key key) const
 Check whether a key is down.
 
constexpr bool isKeyUp (Key key) const
 Check whether a key is up.
 
constexpr void setKeyState (Key key, bool down)
 Update a given key state.
 
- Public Member Functions inherited from ecstasy::IResource
virtual ~IResource ()=default
 Default destructor.
 

Static Public Member Functions

static constexpr void assertKeyValid (Key key, bool allowUnknown=false)
 Check whether a key is valid.
 

Private Attributes

std::array< bool, static_cast< int >(Key::Count)> _keys
 Keyboard keys state.
 

Detailed Description

Current Keyboard state.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 30 of file Keyboard.hpp.

Member Enumeration Documentation

◆ Key

Keyboard keys.

Enumerator
Unknown 

Unhandled key.

The A key.

The B key.

The C key.

The D key.

The E key.

The F key.

The G key.

The H key.

The I key.

The J key.

The K key.

The L key.

The M key.

The N key.

The O key.

The P key.

The Q key.

The R key.

The S key.

The T key.

The U key.

The V key.

The W key.

The X key.

The Y key.

The Z key.

Num0 

The 0 key.

Num1 

The 1 key.

Num2 

The 2 key.

Num3 

The 3 key.

Num4 

The 4 key.

Num5 

The 5 key.

Num6 

The 6 key.

Num7 

The 7 key.

Num8 

The 8 key.

Num9 

The 9 key.

Escape 

The Escape key.

LControl 

The left Control key.

LShift 

The left Shift key.

LAlt 

The left Alt key.

LSystem 

The left OS specific key: window (Windows and Linux), apple (MacOS X), ...

RControl 

The right Control key.

RShift 

The right Shift key.

RAlt 

The right Alt key.

RSystem 

The right OS specific key: window (Windows and Linux), apple (MacOS X), ...

Menu 

The Menu key.

LBracket 

The [ key.

RBracket 

The ] key.

Semicolon 

The ; key.

Comma 

The , key.

Period 

The . key.

Quote 

The ' key.

Slash 

The / key.

Backslash 

The \ key.

Tilde 

The ~ key.

Equal 

The = key.

Hyphen 

The - key (hyphen)

Space 

The Space key.

Enter 

The Enter/Return keys.

Backspace 

The Backspace key.

Tab 

The Tabulation key.

PageUp 

The Page up key.

PageDown 

The Page down key.

End 

The End key.

Home 

The Home key.

Insert 

The Insert key.

Delete 

The Delete key.

Add 

The + key.

Subtract 

The - key (minus, usually from numpad)

Multiply 

The * key.

Divide 

The / key.

Left 

Left arrow.

Right 

Right arrow.

Up 

Up arrow.

Down 

Down arrow.

Numpad0 

The numpad 0 key.

Numpad1 

The numpad 1 key.

Numpad2 

The numpad 2 key.

Numpad3 

The numpad 3 key.

Numpad4 

The numpad 4 key.

Numpad5 

The numpad 5 key.

Numpad6 

The numpad 6 key.

Numpad7 

The numpad 7 key.

Numpad8 

The numpad 8 key.

Numpad9 

The numpad 9 key.

F1 

The F1 key.

F2 

The F2 key.

F3 

The F3 key.

F4 

The F4 key.

F5 

The F5 key.

F6 

The F6 key.

F7 

The F7 key.

F8 

The F8 key.

F9 

The F9 key.

F10 

The F10 key.

F11 

The F11 key.

F12 

The F12 key.

F13 

The F13 key.

F14 

The F14 key.

F15 

The F15 key.

Pause 

The Pause key.

Count 

Keep last – the total number of keyboard keys.

Definition at line 47 of file Keyboard.hpp.

47 {
48 Unknown = -1,
49 A,
50 B,
51 C,
52 D,
53 E,
54 F,
55 G,
56 H,
57 I,
58 J,
59 K,
60 L,
61 M,
62 N,
63 O,
64 P,
65 Q,
66 R,
67 S,
68 T,
69 U,
70 V,
71 W,
72 X,
73 Y,
74 Z,
75 Num0,
76 Num1,
77 Num2,
78 Num3,
79 Num4,
80 Num5,
81 Num6,
82 Num7,
83 Num8,
84 Num9,
85 Escape,
86 LControl,
87 LShift,
88 LAlt,
89 LSystem,
90 RControl,
91 RShift,
92 RAlt,
93 RSystem,
94 Menu,
95 LBracket,
96 RBracket,
97 Semicolon,
98 Comma,
99 Period,
100 Quote,
101 Slash,
102 Backslash,
103 Tilde,
104 Equal,
105 Hyphen,
106 Space,
107 Enter,
108 Backspace,
109 Tab,
110 PageUp,
111 PageDown,
112 End,
113 Home,
114 Insert,
115 Delete,
116 Add,
117 Subtract,
118 Multiply,
119 Divide,
120 Left,
121 Right,
122 Up,
123 Down,
124 Numpad0,
125 Numpad1,
126 Numpad2,
127 Numpad3,
128 Numpad4,
129 Numpad5,
130 Numpad6,
131 Numpad7,
132 Numpad8,
133 Numpad9,
134 F1,
135 F2,
136 F3,
137 F4,
138 F5,
139 F6,
140 F7,
141 F8,
142 F9,
143 F10,
144 F11,
145 F12,
146 F13,
147 F14,
148 F15,
149 Pause,
150
151 Count,
152 };
@ Subtract
The - key (minus, usually from numpad)
@ RSystem
The right OS specific key: window (Windows and Linux), apple (MacOS X), ...
@ Count
Keep last – the total number of keyboard keys.
@ LSystem
The left OS specific key: window (Windows and Linux), apple (MacOS X), ...

Constructor & Destructor Documentation

◆ Keyboard()

ecstasy::integration::event::Keyboard::Keyboard ( )
inlinenoexcept

Construct a new Keyboard resource.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 161 of file Keyboard.hpp.

161: _keys({false}){};
std::array< bool, static_cast< int >(Key::Count)> _keys
Keyboard keys state.
Definition Keyboard.hpp:245

◆ ~Keyboard()

virtual ecstasy::integration::event::Keyboard::~Keyboard ( )
virtualdefaultnoexcept

Destroy the Keyboard.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Member Function Documentation

◆ assertKeyValid()

static constexpr void ecstasy::integration::event::Keyboard::assertKeyValid ( Key  key,
bool  allowUnknown = false 
)
inlinestaticconstexpr

Check whether a key is valid.

Parameters
[in]keyEvaluated key.
[in]allowUnknownWhether the Unknown key is valid or not.
Exceptions
std::invalid_argumentIf the key is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-13)

Definition at line 236 of file Keyboard.hpp.

237 {
238 if (static_cast<size_t>(key) >= static_cast<size_t>(Key::Count) || (!allowUnknown && key == Key::Unknown))
239 [[unlikely]]
240 throw std::invalid_argument("Invalid key");
241 }

◆ isKeyDown()

constexpr bool ecstasy::integration::event::Keyboard::isKeyDown ( Key  key) const
inlineconstexpr

Check whether a key is down.

Parameters
[in]keyevaluated key.
Returns
bool Whether the key is down.
Exceptions
std::invalid_argumentIf the key is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 183 of file Keyboard.hpp.

184 {
185 assertKeyValid(key);
186 return _keys[static_cast<size_t>(key)];
187 }
static constexpr void assertKeyValid(Key key, bool allowUnknown=false)
Check whether a key is valid.
Definition Keyboard.hpp:236

◆ isKeyUp()

constexpr bool ecstasy::integration::event::Keyboard::isKeyUp ( Key  key) const
inlineconstexpr

Check whether a key is up.

Parameters
[in]keyevaluated key.
Returns
bool Whether the key is up.
Exceptions
std::invalid_argumentIf the key is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 201 of file Keyboard.hpp.

202 {
203 return !isKeyDown(key);
204 }
constexpr bool isKeyDown(Key key) const
Check whether a key is down.
Definition Keyboard.hpp:183

◆ setKeyState()

constexpr void ecstasy::integration::event::Keyboard::setKeyState ( Key  key,
bool  down 
)
inlineconstexpr

Update a given key state.

Warning
It only update the internal state, no event is called.
Parameters
[in]keyKey to update.
[in]downWhether the key must be set down or not.
Exceptions
std::invalid_argumentIf the key is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 219 of file Keyboard.hpp.

220 {
221 assertKeyValid(key);
222 _keys[static_cast<size_t>(key)] = down;
223 }

Member Data Documentation

◆ _keys

std::array<bool, static_cast<int>(Key::Count)> ecstasy::integration::event::Keyboard::_keys
private

Keyboard keys state.

Definition at line 245 of file Keyboard.hpp.


The documentation for this class was generated from the following file: