My Project
Keyboard.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** B-CPP-500-PAR-5-1-rtype-martin.vanaud
4 ** File description:
5 ** Keyboard
6 */
7 
8 #ifndef KEYBOARD_HPP_
9 #define KEYBOARD_HPP_
10 
11  #include <raylib.h>
12 
13  #include <utility>
14  #include <map>
15 
20 class Keyboard {
21  public:
26  Keyboard();
27 
32  ~Keyboard();
33 
39  int getKey() const;
47  bool hasBeenPressed(int key) const;
55  bool isBeingPressed(int key) const;
63  bool hasBeenReleased(int key) const;
71  bool isNotBeingPressed(int key) const;
77  void setExitKey(int key);
83  int getPressedKeycode() const;
89  int getPressedCharcode() const;
95  int getKeyUpCharCode() const;
101  int getKeyDownCharCode() const;
107  int getKeyRightCharCode() const;
113  int getKeyLeftCharCode() const;
119  int getKeySpaceCharCode() const;
120 
126  int getKeyEnterCharCode() const;
132  int getKeySCharCode() const;
138  int getKeyDCharCode() const;
139 
140 
148  template<typename ENUM>
149  std::map<ENUM, bool> getKeysPressed(std::map<ENUM, int> map) const
150  {
151  std::map<ENUM, bool> actionPressed;
152  for (auto &[action, key] : map)
153  actionPressed.emplace(action, isBeingPressed(key));
154  return actionPressed;
155  };
156 
164  template<typename ENUM>
165  std::map<ENUM, bool> getKeysHasBeenPressed(std::map<ENUM, int> map) const
166  {
167  std::map<ENUM, bool> actionPressed;
168  for (auto &[action, key] : map)
169  actionPressed.emplace(action, hasbeenReleased(key));
170  return actionPressed;
171  };
172 
173  protected:
174  private:
175  int _key;
176 };
177 
178 
179 
180 #endif /* !KEYBOARD_HPP_ */
Keyboard::~Keyboard
~Keyboard()
Destroy the Keyboard object.
Definition: Keyboard.cpp:14
Keyboard::getKey
int getKey() const
Get the Key value.
Definition: Keyboard.cpp:18
Keyboard::getKeysHasBeenPressed
std::map< ENUM, bool > getKeysHasBeenPressed(std::map< ENUM, int > map) const
Get the Keys Has Been Pressed object.
Definition: Keyboard.hpp:165
Keyboard::hasBeenPressed
bool hasBeenPressed(int key) const
Check if a key has been pressed.
Definition: Keyboard.cpp:23
Keyboard::getKeyEnterCharCode
int getKeyEnterCharCode() const
Get the Key Enter Char Code object.
Definition: Keyboard.cpp:83
Keyboard::getKeyDCharCode
int getKeyDCharCode() const
Get the Key D Char Code object.
Definition: Keyboard.cpp:92
Keyboard::getKeyLeftCharCode
int getKeyLeftCharCode() const
Get the Key Left Key Code object.
Definition: Keyboard.cpp:73
Keyboard::getKeysPressed
std::map< ENUM, bool > getKeysPressed(std::map< ENUM, int > map) const
Get the Keys Pressed object.
Definition: Keyboard.hpp:149
Keyboard::getKeyRightCharCode
int getKeyRightCharCode() const
Get the Key Down Char Code object.
Definition: Keyboard.cpp:68
Keyboard::getKeySCharCode
int getKeySCharCode() const
Get the Key S Char Code object.
Definition: Keyboard.cpp:88
Keyboard::Keyboard
Keyboard()
Construct a new Keyboard object.
Definition: Keyboard.cpp:10
Keyboard::isNotBeingPressed
bool isNotBeingPressed(int key) const
Check if a key is not being pressed.
Definition: Keyboard.cpp:38
Keyboard::isBeingPressed
bool isBeingPressed(int key) const
Check if a key is being pressed.
Definition: Keyboard.cpp:28
Keyboard::getPressedKeycode
int getPressedKeycode() const
Get the Pressed Keycode object.
Definition: Keyboard.cpp:48
Keyboard::hasBeenReleased
bool hasBeenReleased(int key) const
Check if a key has been released.
Definition: Keyboard.cpp:33
Keyboard::getKeyDownCharCode
int getKeyDownCharCode() const
Get the Key Down Key Code object.
Definition: Keyboard.cpp:63
Keyboard
Keyboard class that handles inputs from computer keyboards.
Definition: Keyboard.hpp:20
Keyboard::setExitKey
void setExitKey(int key)
Set the Exit Key object.
Definition: Keyboard.cpp:43
Keyboard::getKeySpaceCharCode
int getKeySpaceCharCode() const
Get the Key Space Char Code object.
Definition: Keyboard.cpp:78
Keyboard::getPressedCharcode
int getPressedCharcode() const
Get the Pressed Charcode object.
Definition: Keyboard.cpp:53
Keyboard::getKeyUpCharCode
int getKeyUpCharCode() const
Get the Key Up Char Code object.
Definition: Keyboard.cpp:58