-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCKeyboardEvents.h
51 lines (38 loc) · 908 Bytes
/
CKeyboardEvents.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
48
49
50
51
#ifndef _CKeyboardEvents_
#define _CKeyboardEvents_
#include "SDL.h"
#include "CInputHandle.h"
class CKeyboardEvents :
public CInputHandle
{
public:
static CKeyboardEvents* Instance()
{
if (s_pInstance == 0)
{
s_pInstance = new CKeyboardEvents();
s_pInstance->update();
}
return s_pInstance;
}
void update();
bool isKeyDown(SDL_Scancode key) const;
/*用户调用函数判断是否按下键*/
static bool ifKeyDown(SDL_Scancode key)
{
Instance()->update();
if (Instance()->isKeyDown(key))
return true;
else
return false;
}
private:
CKeyboardEvents();
~CKeyboardEvents();
CKeyboardEvents(const CKeyboardEvents&);
void onKeyDown();
void onKeyUp();
const Uint8* m_keystates;
static CKeyboardEvents* s_pInstance;
};
#endif