# Multiple Keypress (and hold) detection

**URL:** <https://forum.kirupa.com/t/multiple-keypress-and-hold-detection/225174>\
**Category:** flash\
**Created:** [May 9, 2007, 12:33pm UTC](https://forum.kirupa.com/t/multiple-keypress-and-hold-detection/225174 "2007-05-09T12:33:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayme65](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@Jayme65](https://forum.kirupa.com/u/Jayme65)\
**Post date:** [May 9, 2007, 12:33pm UTC](https://forum.kirupa.com/t/multiple-keypress-and-hold-detection/225174/1 "2007-05-09T12:33:11Z")

</div>

Hi,  
I’have a 2 in 1 problem 😉 Would you please give me some help?  
 ![](http://forum.kirupa.com/uploads/kirupa/3615/5c8dde53bb2ecf29.gif)

## The facts:

1. In this example, when the user press on 1, 2, 3, 4 or 5 on the keypad, the corresponding pushbutton should display a “down” state.  
This should last a couple frames so that the user has some time to see it displayed on stage.
2. The user should be able to press on 1 button, hold it, and press on a second one  
This should be displayed on stage! One must see the first button pressed…followed by the second one (so, 2 buttons pressed consecutively!)

## The problems:

1. I’m now using a couple frames in the timeline of each button to make the “state down” last a little.  
Is there a better way to do it (a “timer” function?)
2. I can’t get the multiple keypress detection work!  
If I press simultaneously it’s working…  
but if I press 1 button, hold it 1 sec, then (without releasing the 1st one) then press the second one:  
the last button is fired, and the first one released!

Please find here the fla to work with, thanks very much by advance!  
[multiple\_keypress.fla](http://users.skynet.be/deboeur/Problems/multiple_keypress.fla)

```auto
function panelDown() {
 if (Key.getCode() == 97) {
  //Keypad 1
  fireEvent(btn1)
 } else if (Key.getCode() == 98) {
  //Keypad 2
  fireEvent(btn2)
 } else if (Key.getCode() == 99) {
  //Keypad 3
  fireEvent(btn3)
 } else if (Key.getCode() == 100) {
  //Keypad 4
  fireEvent(btn4)
 } else if (Key.getCode() == 101) {
  //Keypad 5
  fireEvent(btn5)
 }
}
//
//
var panelListener:Object = new Object();
panelListener.onKeyDown = panelDown;
Key.addListener(panelListener);
//
function fireEvent(mc) {
 mc.gotoAndPlay(2);
}

```
