# keyDown stop giving me the pressed keys

**URL:** https://discourse.libcinder.org/t/keydown-stop-giving-me-the-pressed-keys/1415
**Category:** Using Cinder
**Created:** [January 29, 2019, 10:50am UTC](https://discourse.libcinder.org/t/keydown-stop-giving-me-the-pressed-keys/1415 "2019-01-29T10:50:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MrFlavZz](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@MrFlavZz](https://discourse.libcinder.org/u/MrFlavZz)
#### Post date: [January 29, 2019, 10:50am UTC](https://discourse.libcinder.org/t/keydown-stop-giving-me-the-pressed-keys/1415/1 "2019-01-29T10:50:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![balachandran\_c](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@balachandran\_c](https://discourse.libcinder.org/u/balachandran_c)
#### Post date: [January 29, 2019, 2:05pm UTC](https://discourse.libcinder.org/t/keydown-stop-giving-me-the-pressed-keys/1415/2 "2019-01-29T14:05:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![MrFlavZz](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@MrFlavZz](https://discourse.libcinder.org/u/MrFlavZz)
#### Post date: [January 30, 2019, 9:42am UTC](https://discourse.libcinder.org/t/keydown-stop-giving-me-the-pressed-keys/1415/3 "2019-01-30T09:42:01Z")

</div>

Haaaa thanks you,

Your way of working perfectly, thank you very much.
