Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
keyboard_state.h
1 #pragma once
2 
3 #include "win32/key_code.h"
4 
5 #include "util/map.h"
6 #include "util/queue.h"
7 
8 namespace blowbox
9 {
19  {
20  friend class GLFWManager;
21  friend class Window;
22  friend class ImGuiManager;
23  public:
30  struct KeyState
31  {
32  bool down = false;
33  bool pressed = false;
34  bool released = false;
35  bool modifier_control = false;
36  bool modifier_alt = false;
37  bool modifier_shift = false;
38  };
39 
40  KeyboardState();
41  ~KeyboardState();
42 
48  bool GetKey(KeyCode key);
49 
55  bool GetKeyDown(KeyCode key);
56 
62  bool GetKeyPressed(KeyCode key);
63 
69  bool GetKeyReleased(KeyCode key);
70 
76  const KeyState& GetKeyState(KeyCode key);
77 
83 
84  protected:
89  void SetKeyPressed(KeyCode key);
90 
95  void SetKeyReleased(KeyCode key);
96 
102  void SetKeyModifiers(KeyCode key, int modifiers);
103 
108  void AddInputKey(unsigned int key);
109 
111  void ResetKeys();
112  private:
115  };
116 }
void SetKeyModifiers(KeyCode key, int modifiers)
Changes the key modifiers of a key to true.
Definition: keyboard_state.cc:74
bool modifier_alt
Whether the alt-modifier was pressed together with this key.
Definition: keyboard_state.h:36
Queue< unsigned int > input_keys_
The keys that were pressed over the last frame, in correct order. These are stored in unicode ids...
Definition: keyboard_state.h:114
Implements all ImGui functionality.
Definition: imgui_manager.h:22
Class for creating windows.
Definition: window.h:30
bool GetKeyDown(KeyCode key)
Find out whether a key is down or not.
Definition: keyboard_state.cc:30
bool GetKey(KeyCode key)
Find out whether a key is down or not.
Definition: keyboard_state.cc:24
void SetKeyPressed(KeyCode key)
Changes the press-state of a key to true.
Definition: keyboard_state.cc:60
eastl::map< Key, T > Map
Typedef for wrapping the EASTL map.
Definition: map.h:14
bool GetKeyReleased(KeyCode key)
Find out whether a key is released or not.
Definition: keyboard_state.cc:42
bool released
Whether the key is currently released. (only true for 1 frame!)
Definition: keyboard_state.h:34
const KeyState & GetKeyState(KeyCode key)
Retrieves the full state of a key.
Definition: keyboard_state.cc:48
KeyCode
All keycodes.
Definition: key_code.h:12
Keeps track of the state of the keyboard.
Definition: keyboard_state.h:18
void AddInputKey(unsigned int key)
Adds an input key.
Definition: keyboard_state.cc:82
bool pressed
Whether the key is currently pressed. (only true for 1 frame!)
Definition: keyboard_state.h:33
void ResetKeys()
Resets all keys by changing their press & release states to false.
Definition: keyboard_state.cc:88
eastl::queue< T > Queue
Typedef for wrapping the EASTL queue.
Definition: queue.h:14
bool GetKeyPressed(KeyCode key)
Find out whether a key is pressed or not.
Definition: keyboard_state.cc:36
The main Blowbox namespace.
Definition: image.cc:8
Map< KeyCode, KeyState > key_states_
A map of KeyCodes to KeyStates.
Definition: keyboard_state.h:113
void SetKeyReleased(KeyCode key)
Changes the release-state of a key to true.
Definition: keyboard_state.cc:67
Queue< unsigned int > GetInputKeys() const
Definition: keyboard_state.cc:54
Manages all GLFW state such as global initialization / termination, event polling, etc.
Definition: glfw_manager.h:16
bool modifier_control
Whether the control-modifier was pressed together with this key.
Definition: keyboard_state.h:35
bool modifier_shift
Whether the shift-modifier was pressed together with this key.
Definition: keyboard_state.h:37
Keeps track of the state of a key on the keyboard.
Definition: keyboard_state.h:30
bool down
Whether the key is currently held down.
Definition: keyboard_state.h:32