Keyboard Event Question

Hi, I have a question regarding the use of ActionScript 3.0 and keyboard events.

I’m trying to make so that if a key is pressed (the ESC/Escape key to be specific), a movie clip on the frame with the code will go to its next frame.

From what I understand it should be something like this:

stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyboard, false, 1, true);

function handleKeyboard(e:KeyboardEvent):void {
    if(e.keyCode == Keyboard.ESCAPE) {
        panel.gotoAndPlay(nextFrame);
    }
}

It’s the code I am using and it works oddly. When I press the ESC key when I am in the .SWF normally, nothing happens. After I press a button symbol and press the ESC key, it does work. Of course, I want it to work so that it will work at any time, whether I have a button pressed previously or not.

There are some other problems I am having but will get to those after this one is resolved. If necessary I will share a .FLA file of what I have now, but only if necessary.

Thanks in advance.