-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyManager.cpp
More file actions
73 lines (64 loc) · 1.35 KB
/
KeyManager.cpp
File metadata and controls
73 lines (64 loc) · 1.35 KB
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
#include "KeyManager.h"
HRESULT KeyManager::Init()
{
keyUp.set();
keyDown.reset();
//for (int i = 0; i < MAX_KEY_COUNT; i++)
//{
// keyUp[i] = true;
// keyDown[i] = false;
//}
return S_OK;
}
void KeyManager::Release()
{
ReleaseInstance();
}
bool KeyManager::IsOnceKeyDown(int key)
{
//GetAsyncKeyState(VK_BACK)
/*
함수 호출 시점에 가상키 (VK_...)가 어떤 상태인지 확인
1. 0x0000 -> 이전 프레임에 누른적이 없고 호출시점에도 눌려있지 않음
2. 0x0001 -> 이전 프레임에 누른적이 있고 호출시점에는 눌려있지 않음
3. 0x8000 -> 이전 프레임에 누른적이 없고 호출시점에는 눌려있는 상태
4. 0x8001 -> 이전 프레임에 누른적이 있고 호출시점에도 눌렸있는 상태
*/
if (GetAsyncKeyState(key) & 0x8000)
{
if (keyDown[key] == false)
{
keyDown[key] = true;
return true;
}
}
else
{
keyDown[key] = false;
}
return false;
}
bool KeyManager::IsOnceKeyUp(int key)
{
if (GetAsyncKeyState(key) & 0x8000)
{
keyUp[key] = false;
}
else
{
if (keyUp[key] == false)
{
keyUp[key] = true;
return true;
}
}
return false;
}
bool KeyManager::IsStayKeyDown(int key)
{
if (GetAsyncKeyState(key) & 0x8000)
{
return true;
}
return false;
}