-
Notifications
You must be signed in to change notification settings - Fork 1
/
Keyboard.cpp
57 lines (49 loc) · 1.11 KB
/
Keyboard.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
#include "Keyboard.h"
#include "Defines.h"
namespace RTG
{
Keyboard::Keyboard()
{
MAPIL::ZeroObject( m_PrevKeys, sizeof( m_PrevKeys ) );
MAPIL::ZeroObject( m_Keys, sizeof( m_Keys ) );
}
Keyboard::~Keyboard()
{
MAPIL::ZeroObject( m_PrevKeys, sizeof( m_PrevKeys ) );
MAPIL::ZeroObject( m_Keys, sizeof( m_Keys ) );
}
void Keyboard::Update()
{
MAPIL::GetKeyboardState( m_Keys );
for( int i = 0; i < 256; ++i ){
if( MAPIL::HasKeyPushedStatus( m_Keys[ i ] ) ){
if( m_PrevKeys[ i ] == KEY_STATE_ONCE ){
m_PrevKeys[ i ] = KEY_STATE_KEEP;
}
else if( m_PrevKeys[ i ] == KEY_STATE_NO_PUSHED ){
m_PrevKeys[ i ] = KEY_STATE_ONCE;
}
}
else{
m_PrevKeys[ i ] = KEY_STATE_NO_PUSHED;
}
}
}
bool Keyboard::IsPushedOnce( int key ) const
{
return m_PrevKeys[ key ] == KEY_STATE_ONCE ? true : false;
}
bool Keyboard::IsPushed( int key ) const
{
return m_PrevKeys[ key ] == KEY_STATE_NO_PUSHED ? false : true;
}
int Keyboard::GetKeyPushedOnce() const
{
for( int i = 0; i < 256; ++i ){
if( m_PrevKeys[ i ] == KEY_STATE_ONCE ){
return i;
}
}
return -1;
}
}