00001
#include "StdAfx.h"
00002
#include "Keyboard.h"
00003
00004 CKeyboard::CKeyboard()
00005 {
00006
m_uipKeys =
new UINT[256];
00007
m_uiKeyCount = 256;
00008 }
00009
00010 CKeyboard::~CKeyboard()
00011 {
00012
Destroy();
00013 }
00014
00015 int CKeyboard::Create()
00016 {
00017
#ifdef DIRECT_INPUT
00018
if(m_pDIDevice == NULL)
00019 {
00020 HRESULT Result = g_pDI->CreateDevice(GUID_SysKeyboard, &m_pDIDevice, NULL);
00021
if(FAILED(Result))
00022
return 0;
00023
00024
00025 m_pDIDevice->SetDataFormat( &c_dfDIKeyboard );
00026
return 1;
00027 }
00028
#endif
00029
00030
return 1;
00031 }
00032
00033 UINT
CKeyboard::Poll()
00034 {
00035
if(m_uipKeys == NULL)
00036
return 0;
00037
00038
#ifndef DIRECT_INPUT
00039
ZeroMemory(m_uipKeys,
sizeof(UINT) * 256);
00040 GetKeyboardState((BYTE *)m_uipKeys);
00041
#else
00042
if(m_pDIDevice !=NULL)
00043 {
00044 m_pDIDevice->Acquire();
00045 ZeroMemory(m_uipKeys,
sizeof(UINT) * 256);
00046
00047 HRESULT Result = m_pDIDevice->GetDeviceState(
sizeof(UINT) * 256, &m_uipKeys);
00048 }
00049
#endif
00050
00051
return 1;
00052 }
00053
00054 UINT
CKeyboard::GetKeyState(UINT uiKeyIndex)
00055 {
00056
if(m_uipKeys !=NULL)
00057 {
00058
if(uiKeyIndex >=0 && uiKeyIndex < m_uiKeyCount)
00059
return m_uipKeys[uiKeyIndex];
00060 }
00061
00062
return 0;
00063 }
00064
00065 bool CKeyboard::IsKeyDown(
char cKey)
00066 {
00067
return (m_uipKeys[cKey] == KEY_DOWN);
00068 }
00069
00070 bool CKeyboard::IsKeyUp(
char cKey)
00071 {
00072
return (m_uipKeys[cKey] == KEY_UP);
00073 }
00074
00075 void CKeyboard::Destroy()
00076 {
00077
00078 }
00079
00080 bool CKeyboard::IsOfType(eEntityType eType)
00081 {
00082
if(eType == Entity_Keyboard)
00083
return true;
00084
00085
return CEntity::IsOfType(eType);
00086 }