Jump to content
  • Advertisement
Sign in to follow this  
Endar

Problem with winuser.h

This topic is 4920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

// 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.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!