开发者

event.keyCode doesn't work for enter key

I've read that the enter keycode should be 13. However when using

trace(event.keyCode);

other keys will show up but the enter key does not. Could it be my computer or something? Using macbook pro keyboard.

stage.addEventListener(KeyboardEvent.KEY_DOWN, entered);

function entered(event:KeyboardEvent):void {
    trace(event.keyCode);
    if (event.keyCode == Keyboard.ENTER){
    //or if (event.keyCode == 13){
        trace("enter button");
    }
开发者_StackOverflow}

i.e. I can't get this to trace "enter button" Also noticed no code traceable for Ctrl. alt Tab or Backpace


Actually, I believe noone here really tried it ^^.

My guess: you're running this via run movie (Cmd+Return) command. If my guess is right, in Flash Application Bar (while your application is running) go into Commands->Disable Keyboard shortcuts.

^^

What's happening: Flash player (or fpdebug) has some keyboard shortcuts, which, if pressed, act as keyboard shortcuts for flash and do not reach your movie. Enter is shortcut for 'Play Movie'.


Are you compiling this in Flash?
If so, this is, probably, the problem...

Flash Debug Player intercepts some key presses.
To get rid of it, check "Disable keyboard shortcuts" in Controls menu of the player.

My Flash is in Portuguese, but you should find it easily.

event.keyCode doesn't work for enter key


Does the first trace show "13" when you press the enter key? Or doesn't pressing ENTER trigger any traces?

I used pretty much the same code in a project of mine, the only difference is that I listen for KEY_UP instead of KEY_DOWN. Does that make a difference?

There's another possibility: maybe some other object listens for KEY_DOWN Events from the stage too, and prevents those Events from propagating to your event listener.


This is almost certainly a focus problem, with another application receiving the enter keypresses instead of Flash. Are you running this in a browser or the standalone player?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜