Input help

Started by
6 comments, last by 31337noob 18 years, 5 months ago
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?
Advertisement
You have your true and false switched around in your macro
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
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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?
does anyone know how to fix it?
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 oncebool 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;}
thanks. it worked

This topic is closed to new replies.

Advertisement