keyDown stop giving me the pressed keys


#1

Hello guys (it’s me again ^^),

I explain my problem, I want that when the user presses “a” it displays a menu and when it presses “b” it displays a window (for example) but if it remains press “a” it continues a display a menu ,

void SometApp::keyDown(KeyEvent event)

{

app:console() << event.getCode() << endl;
switch (event.getCode())
{

case 98: {
	if(keyPressedBefore == 97){
	//some stuff
	}		
	break;
}
case 97: {
	keyPressedBefore = 97;
	break;
}
default:
	break;
}  

}

So if i press “a” then “b” then i stop press “b” the programm will display 97 then 98 then nothing ,while I would like it to display 97.

Is there a way to fix my problem ? Or I have to turn to a simpler solution ?

Thank you very much for your feedback


#2

Hi,

Even though I might not have understood your problem clearly, may I share my thoughts on organizing the code? I would use the keyDown and keyUp methods to track the active state of the keys that I care about. Say, isKeyFunctionADown or isKeyFunctionBDown. On keyDown you can set it to true, and on keyUp you could set it to false. In my update method, I would call a method that looks at this set of key states together and takes the correct action. For example if( isKeyFunctionADown && !isKeyFunctionBDown ) then do x;. Hope this is useful,
Bala.


#3

Haaaa thanks you,

Your way of working perfectly, thank you very much.