-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyStateHandler.cpp
66 lines (57 loc) · 1.44 KB
/
KeyStateHandler.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
#include "KeyStateHandler.h"
#include<Windows.h>
void KeyStateHandler::update(int key, int clk)
{
if (clk != clock[key]) {
previousState[key] = currentState[key];
clock[key] = clk;
currentState[key] = GetKeyState(key);
}
}
bool KeyStateHandler::clickedDown(int key, int clk)
{
update(key, clk);
return (currentState[key]<0 != previousState[key]<0) && (currentState[key] < 0);
}
bool KeyStateHandler::clickedUp(int key, int clk)
{
update(key, clk);
return (currentState[key]<0 != previousState[key]<0) && (currentState[key] >= 0);
}
bool KeyStateHandler::pressing(int key, int clk)
{
update(key, clk);
return currentState[key] < 0;
}
bool KeyStateHandler::clickedDownOrUp(int key, int clk)
{
update(key, clk);
return (currentState[key] < 0 != previousState[key] < 0);
}
bool KeyStateHandler::pressingAnyOf(vector<int> keys, int clk)
{
for (auto key : keys) {
if (pressing(key, clk)) {
return true;
}
}
return false;
}
bool KeyStateHandler::pressingAllOf(vector<int> keys, int clk)
{
for (auto key : keys) {
if (!pressing(key, clk)) {
return false;
}
}
return true;
}
bool KeyStateHandler::clickedDownAnyOf(vector<int> keys, int clk)
{
for (auto key : keys) {
if (clickedDown(key, clk)) {
return true;
}
}
return false;
}