# Is this a correct way to capture keys?

**URL:** <https://forum.kirupa.com/t/is-this-a-correct-way-to-capture-keys/225731>\
**Category:** flash\
**Created:** [May 15, 2007, 7:49am UTC](https://forum.kirupa.com/t/is-this-a-correct-way-to-capture-keys/225731 "2007-05-15T07:49:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![costa](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@costa](https://forum.kirupa.com/u/costa)\
**Post date:** [May 15, 2007, 7:49am UTC](https://forum.kirupa.com/t/is-this-a-correct-way-to-capture-keys/225731/1 "2007-05-15T07:49:00Z")

</div>

Dear all,

I want to capture when arrow up and arrow down are pressed. The idea is while these keys are pressed I will move a movieClip. This is what I did:

```auto
stage.addEventListener(KeyboardEvent.KEY_UP,key_Up);
stage.addEventListener(KeyboardEvent.KEY_DOWN,key_Down);
stage.addEventListener(Event.ENTER_FRAME,mainLoop);

function key_Up(event:KeyboardEvent) {
	keyPressed=-1;
}

function key_Down(event:KeyboardEvent) {
	keyPressed = event.keyCode;
}

function mainLoop(event:Event) {
	if (keyPressed ==38) {
		trace("ArrowUp")
	}
	if (keyPressed==40) {
		trace("ArrowDown")
	}
}

```

Thanks in advance for feedback
