Sign in to follow this  
31337noob

Input help

Recommended Posts

31337noob    101
what is wrong with this?
#define  KeyUp(data, n)    ((data[n] & 0x80) ? false : true)

unsigned char key[256];
bool keyDown = false;

bool Input::getKeyPressed(unsigned char KEY)
{
	if(KeyUp(key,KEY))
		return false;

	return true;
}

//code to check to see if they pressed it once
bool ButtonAndKey::KeyPressUp(unsigned char Key)
{
	if(g_engine->getInput()->getKeyPressed(Key) && !keyDown)
	{
		keyDown = true;
	}
	if(!g_engine->getInput()->getKeyPressed(Key) && keyDown)
	{
		keyDown = false;
		return true;
	}

	return false;
}



here is what i am using it with
if(bk->KeyPressUp(DIK_F1))
 PostQuitMessage( 0 );
if(bk->KeyPressUp(DIK_GRAVE))
 Error("Debug Console");


when i hit the ` key it does the PostQuitMessage and when i hit F1 it gives me the messagebox. so my question is this. WHY ARE THE REVERSED?

Share this post


Link to post
Share on other sites
31337noob    101
no i dont

#define KeyDown(data, n) ((data[n] & 0x80) ? true : false)
#define KeyUp(data, n) ((data[n] & 0x80) ? false : true)

and if i switch it they dont work right

Share this post


Link to post
Share on other sites
31337noob    101
Quote:
Original post by Endurion
I'd guess that you need to implement the keyDown for every key, not one bool for all keys. Otherwise they interfere with different keyDown calls.


can you give an example?

Share this post


Link to post
Share on other sites
chadmv    645
Quote:
Original post by chadmv
You have your true and false switched around in your macro


Oops, I looked too fast and thought it was a KeyDown macro...my bad.

Quote:
Original post by 31337noob
Quote:
Original post by Endurion
I'd guess that you need to implement the keyDown for every key, not one bool for all keys. Otherwise they interfere with different keyDown calls.


can you give an example?


He's saying something like:
#define  KeyUp(data, n)    ((data[n] & 0x80) ? false : true)

unsigned char key[256];
bool keyDown[256];

bool Input::getKeyPressed(unsigned char KEY)
{
if(KeyUp(key,KEY))
return false;

return true;
}

//code to check to see if they pressed it once
bool ButtonAndKey::KeyPressUp(unsigned char Key)
{
if(g_engine->getInput()->getKeyPressed(Key) && !keyDown[Key])
{
keyDown[Key] = true;
}
if(!g_engine->getInput()->getKeyPressed(Key) && keyDown[Key])
{
keyDown[Key] = false;
return true;
}

return false;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this