// CWinKeyboardInput.h
#ifndef _CWIN_KEYBOARD_INPUT_H_
#define _CWIN_KEYBOARD_INPUT_H_
#include <memory.h>
#include <winuser.h>
class CWinKeyboardInput
{
private:
typedef short WINKEYBSTATE[256];
typedef short* LPWINKEYBSTATE;
LPWINKEYBSTATE pck;
LPWINKEYBSTATE pok;
WINKEYBSTATE ks1;
WINKEYBSTATE ks2;
typedef char BYTE;
CWinKeyboardInput()
{
GetKeyboardState(ks1);
memcpy(ks2, ks1, sizeof(WINKEYBSTATE) );
pck = ks1;
pok = ks2;
}
public:
static CWinKeyboardInput& Get()
{
static CWinKeyboardInput k;
CWinKeyboardInput& ref = k;
return ref;
}
void GetKeyboardState(LPWINKEYBSTATE pks)
{
for(int vk=0; vk < 256; vk++)
pks[vk] = GetKeyState(vk);
}
short GetKeyState(BYTE vkey)
{
return GetAsyncKeyState(vkey);
}
void Update()
{
LPWINKEYBSTATE tmp = pck;
pck = pok;
pok = tmp;
GetKeyboardState(pck);
}
bool KeyDown(BYTE vkey)
{
return KeyDown(pck, vkey);
}
bool KeyDown(LPWINKEYBSTATE pk, BYTE vkey)
{
short DOWNMASK = (short)(1 << (8 * sizeof(short)-1) );
return ((pk[vkey]&DOWNMASK) != 0);
}
bool KeyUp(BYTE vkey)
{
return KeyUp(pck, vkey);
}
bool KeyUp(LPWINKEYBSTATE pk, BYTE vkey)
{
return (!KeyDown(pk, vkey));
}
bool KeyPressed(BYTE vkey)
{
return ( KeyUp(pok,vkey) && KeyDown(pck,vkey) );
}
bool KeyReleased(BYTE vkey)
{
return ( KeyDown(pok,vkey) && KeyUp(pck,vkey) );
}
unsigned int VKeyToChar(BYTE vkey)
{
return ((unsigned int) MapVirtualKey(vkey,2) );
}
short CharToVKey(unsigned char ch)
{
return ((BYTE) VkKeyScan(ch) );
}
};
#endif
// Cpp file
#include <iostream>
using namespace std;
#include "CWinKeyboardInput.h"
int main()
{
// create CWinKeyboardInput object
CWinKeyboardInput::Get();
while( 1 ){
CWinKeyboardInput::Get().Update();
if( CWinKeyboardInput::Get().KeyDown('A') )
cout << " Key 'a' pressed!! " << endl;
}
return 0;
}
My problem is that when I try to compile the cpp file, I get a syntax error on line 39 of the "winuser.h" file. It says it misses ';' before identifier 'HDWP' on this line:
typedef HANDLE HDWP;
And I can't readily see a cause in my code for it. May be you guys will be able to see something I can't.
Any help you can give would be appreciated.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper