GameKit
0.0.1a
C++ gamedev tools
include
gk
core
input
InputHandler.hpp
Go to the documentation of this file.
1
/*
2
* =====================================================================================
3
*
4
* Filename: InputHandler.hpp
5
*
6
* Description:
7
*
8
* Created: 17/01/2018 19:09:57
9
*
10
* Author: Quentin Bazin, <quent42340@gmail.com>
11
*
12
* =====================================================================================
13
*/
14
#ifndef GK_INPUTHANDLER_HPP_
15
#define GK_INPUTHANDLER_HPP_
16
17
#include <map>
18
19
#include "
gk/core/IntTypes.hpp
"
20
21
namespace
gk
{
22
23
using
GameKey
=
u32
;
24
29
class
InputHandler
{
30
public
:
31
virtual
~InputHandler
() =
default
;
32
41
virtual
bool
isKeyPressed
(
GameKey
key) {
return
m_keysPressed
[key]; }
42
51
virtual
bool
isKeyPressedOnce
(
GameKey
key);
52
62
virtual
bool
isKeyPressedWithDelay
(
GameKey
key,
u16
delay);
63
70
const
std::map<GameKey, bool> &
keysPressed
()
const
{
return
m_keysPressed
; }
71
72
protected
:
79
void
addKey
(
GameKey
key);
80
82
// Member data
84
std::map<GameKey, bool>
m_keysPressed
;
85
std::map<GameKey, bool>
m_keysPressedOnce
;
86
std::map<GameKey, u32>
m_lastTimePressed
;
87
};
88
89
}
// namespace gk
90
91
#endif // GK_INPUTHANDLER_HPP_
92
gk::InputHandler
Give access to the real time state of an input device (keyboard, gamepad, etc...) ...
Definition:
InputHandler.hpp:29
gk
Definition:
AudioPlayer.hpp:21
gk::InputHandler::~InputHandler
virtual ~InputHandler()=default
u16
unsigned short u16
Definition:
IntTypes.hpp:22
gk::InputHandler::isKeyPressedWithDelay
virtual bool isKeyPressedWithDelay(GameKey key, u16 delay)
Check if a key is pressed with delay.
Definition:
InputHandler.cpp:33
gk::InputHandler::m_keysPressed
std::map< GameKey, bool > m_keysPressed
Keys state.
Definition:
InputHandler.hpp:84
gk::InputHandler::isKeyPressedOnce
virtual bool isKeyPressedOnce(GameKey key)
Check if a key is pressed only one time.
Definition:
InputHandler.cpp:19
gk::InputHandler::isKeyPressed
virtual bool isKeyPressed(GameKey key)
Check if a key is pressed.
Definition:
InputHandler.hpp:41
gk::InputHandler::keysPressed
const std::map< GameKey, bool > & keysPressed() const
Get current keys state.
Definition:
InputHandler.hpp:70
u32
unsigned int u32
Definition:
IntTypes.hpp:23
gk::InputHandler::m_lastTimePressed
std::map< GameKey, u32 > m_lastTimePressed
Keys state for isKeyPressedWithDelay.
Definition:
InputHandler.hpp:86
gk::InputHandler::m_keysPressedOnce
std::map< GameKey, bool > m_keysPressedOnce
Keys state for isKeyPressedOnce.
Definition:
InputHandler.hpp:85
gk::GameKey
u32 GameKey
Alias for game key type.
Definition:
InputHandler.hpp:23
gk::InputHandler::addKey
void addKey(GameKey key)
Add a new key to this input handler.
Definition:
InputHandler.cpp:43
IntTypes.hpp
Generated by
1.8.12