Sleeping Wombat GUI  0.100
swGUI
KeyboardState.h
Go to the documentation of this file.
1 #pragma once
2 
9 #include "InputDeviceEvent.h"
10 #include "KeyState.h"
11 
12 #include <vector>
13 
14 
15 namespace sw {
16 namespace input
17 {
18 
19 
21 
22 
27 {
28 private:
29 
31 
32 public:
33  explicit KeyboardState ();
34  ~KeyboardState ();
35 
38  const KeyState* GetKeyboardState() const { return m_keyboardState; }
39 
41  const KeyState& operator[] ( Keyboard::PhysicalKeys key ) const { return m_keyboardState[ key ]; }
42 
46  void RemoveEvents ();
48 
50  void ApplyEvent ( const DeviceEvent& event );
51 
52 public:
53 
54 };
55 
56 
57 
60 {
61  for( auto& val : m_keyboardState )
62  val = 0;
63 }
64 
67 {}
68 
72 {
73  for( int i = 0; i < KEYBOARD_STATE_KEYS_NUMBER; ++i )
74  m_keyboardState[ i ].HoldState();
75 }
76 
77 
78 // ================================ //
79 //
80 inline void KeyboardState::ApplyEvent ( const DeviceEvent& event )
81 {
83  {
84  const KeyEvent& keyEvent = event.Key;
85  KeyState& state = m_keyboardState[ keyEvent.Key ];
86  state = keyEvent.State.IsPressed();
87  }
88 }
89 
90 
91 
92 
93 
94 } // input
95 } // sw
96 
const KeyState & operator[](Keyboard::PhysicalKeys key) const
Access state of specific key.
Definition: KeyboardState.h:41
KeyState m_keyboardState[KEYBOARD_STATE_KEYS_NUMBER]
Definition: KeyboardState.h:30
Definition: DirectInputModule.cpp:11
KeyState State
Only up or down state.
Definition: InputDeviceEvent.h:276
void RemoveEvents()
Removes information about pressed or unpressed buttons. Key states remain unchanged.
Definition: KeyboardState.h:71
Keyboard::PhysicalKeys Key
Definition: InputDeviceEvent.h:277
const uint8 KEYBOARD_STATE_KEYS_NUMBER
Definition: KeyboardState.h:20
KeyStates changed events.
Definition: InputDeviceEvent.h:313
const KeyState * GetKeyboardState() const
Gets array with keyboard state. Array has size KEYBOARD_STATE_KEYS_NUMBER. You can use Keyboard::Phys...
Definition: KeyboardState.h:38
KeyboardState()
Definition: KeyboardState.h:59
~KeyboardState()
Definition: KeyboardState.h:66
State of keyboard buttons.
Definition: KeyboardState.h:26
void ApplyEvent(const DeviceEvent &event)
Sets state depending on event.
Definition: KeyboardState.h:80
Button state structure..
Definition: KeyState.h:26
uint8_t uint8
Definition: TypesDefinitions.h:27
bool IsPressed() const
Definition: KeyState.h:45
Keyboard key change event.
Definition: InputDeviceEvent.h:274
DeviceEventType Type
Definition: InputDeviceEvent.h:324
KeyState * KeysState()
Definition: KeyboardState.h:45
PhysicalKeys
Physical keys numbers. Numbers are the same as in DirectInput.
Definition: InputDeviceEvent.h:29