-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputManager.cpp
78 lines (76 loc) · 1.6 KB
/
InputManager.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "KeyboardInput.cpp"
#include "MouseInput.cpp"
#include <unordered_map>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
class InputManager
{
public:
enum keyState
{
Idle,
Pressed,
Held,
Released
};
bool setBinds(string Actions,int key);
void Update();
void ResetKeyState(int V_Key);
keyState GetKeyState(int V_Key);
int WhichKey();
vector<int> WhichKeyMultiple();
unordered_map<string,int> keyBinds;
private:
unordered_map<int, keyState> keyStates;
unordered_map<int, bool> lastkeyStates;
set<int> usedKeys;
};
bool InputManager::setBinds(string Actions,int key)
{
if(usedKeys.find(key) != usedKeys.end()){
return false;
}
keyBinds[Actions] = key;
usedKeys.insert(key);
return true;
}
void InputManager::Update()
{
for (int key = 0x01; key <= 0xFE; ++key)
{
bool isPressed = IsKeyDown(key);
if (isPressed)
{
if (!lastkeyStates[key])
{
keyStates[key] = Pressed;
}
else
{
keyStates[key] = Held;
}
}
else
{
if (lastkeyStates[key])
{
keyStates[key] = Released;
}
else
{
keyStates[key] = Idle;
}
}
lastkeyStates[key] = isPressed;
}
}
void InputManager::ResetKeyState(int V_Key)
{
keyStates[V_Key] = Idle;
}
InputManager::keyState InputManager::GetKeyState(int V_Key)
{
return keyStates[V_Key];
}