Sign in to follow this  

Input help

This topic is 4414 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

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

This topic is 4414 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.

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