-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardInput.h
47 lines (34 loc) · 927 Bytes
/
KeyboardInput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <windows.h>
// Standard library C-style
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <functional>
typedef struct
{
bool isPressed;
float pressedDuration;
std::function<void ( WORD key, short status )> onPressCallback;
} keyEventStatus, *pKeyEventStatus;
class KeyboardInput
{
public:
KeyboardInput ( );
KeyboardInput ( HANDLE bufferHandle );
~KeyboardInput ( );
void tick ( const float deltaTime );
bool registerKey ( WORD key );
bool registerOnKey ( WORD key, std::function<void ( WORD, short )> callback );
bool wasPressedThisFrame ( WORD key );
bool isPressed ( WORD key );
// Call this whenever the scene loads to ensure that key holds are reset
void resetKeyPresses ( );
private:
HANDLE m_bufferHandle = nullptr;
BOOL m_ready = false;
DWORD fdwSaveOldMode = 0;
void init ( );
std::map<WORD, pKeyEventStatus> m_keyRegistrations;
};