# \[AS3\] keyboard event wont work :(

**URL:** <https://forum.kirupa.com/t/as3-keyboard-event-wont-work/208260>\
**Category:** flash\
**Created:** [November 27, 2006, 2:05am UTC](https://forum.kirupa.com/t/as3-keyboard-event-wont-work/208260 "2006-11-27T02:05:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mad\_man](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mad\_man](https://forum.kirupa.com/u/mad_man)\
**Post date:** [November 27, 2006, 2:05am UTC](https://forum.kirupa.com/t/as3-keyboard-event-wont-work/208260/1 "2006-11-27T02:05:08Z")

</div>

I decided to pick up a copy of O’reilly Actionscript 3 Cookbook today, and I have been going through. One of the first examples it has for keyboard events is:

```auto

package {
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    
    public class ExampleApplication extends Sprite {
        public function ExampleApplication( ) {
            stage.focus = this;
            addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }
        
        private function onKeyDown(event:KeyboardEvent):void {
            trace("key down: " + event.charCode);
        }
    }
}

```

But for some reason it will not work. According to the book stage.focus = this; is all you need for keyboard events to work, am i doing something wrong?
