# Keyboard combinations

**URL:** <https://forum.kirupa.com/t/keyboard-combinations/276555>\
**Category:** Uncategorized\
**Created:** [November 30, 2008, 8:54pm UTC](https://forum.kirupa.com/t/keyboard-combinations/276555 "2008-11-30T20:54:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jet\_jmu](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jet\_jmu](https://forum.kirupa.com/u/jet_jmu)\
**Post date:** [November 30, 2008, 8:54pm UTC](https://forum.kirupa.com/t/keyboard-combinations/276555/1 "2008-11-30T20:54:16Z")

</div>

Hi everyone,

I’m working on a project that involves using different combinations of the LEFT DOWN and RIGHT keys to interact with a trumpet on screen. I’m having trouble getting flash to recognize different key combinations though. I found this code in the forums:

var aKeysPressed:Array = new Array();

stage.addEventListener( KeyboardEvent.KEY\_DOWN, handleKeyDown );  
stage.addEventListener( KeyboardEvent.KEY\_UP, keyUp );

function handleKeyDown( event:KeyboardEvent ):void {  
aKeysPressed.push( event.keyCode );  
}

function keyUp(event:KeyboardEvent):void {  
// 37 = LEFT, 38 = UP, 39 = RIGHT  
if ( aKeysPressed.length == 2 ) {

```
    if ( aKeysPressed[0] == 37 || aKeysPressed[1] == 37 ) {
        if ( aKeysPressed[0] == 38 || aKeysPressed[1] == 38) {
            trace( " LEFT & UP pressed!" );
        }
        
    } else if ( aKeysPressed[0] == 38 || aKeysPressed[1] == 38 ) {
        if ( aKeysPressed[0] == 39 || aKeysPressed[1] == 39 ) {

            trace( " UP & RIGHT pressed!" );
        }
    }
    
}
aKeysPressed = [];

```

}

but it doesn’t recognize the combinations unless you press the combination all together. I want something to recognize when a combination is pressed, even if one of the keys was already down. I’ve found some other methods, but I feel as though they are a little over my head. Any help would be greatly appreciated.

Thank you!
