Not getting key code for alt key flash AS3

597 views Asked by At

I am having some trouble in getting key code for alt key. Can Anyone help in it. I am sharing for source code the way I am trying to do it.

import flash.events.KeyboardEvent;

stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent){
  trace("Key== "+e.keyCode); 
  txt.text=""+e.keyCode;
});
1

There are 1 answers

1
ChessMax On

There is no key code for alt key. Instead, your should use KeyboardEvent#altKey getter, to check is alt key down or not.

stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent){
    if (e.altKey)
    {
        trace("Alt key is down");
    }
});