0

我想识别按下的大组合键

Ctrl + Alt + Shift + D

例如,在动作脚本中打开一些复活节彩蛋。

4

1 回答 1

0

使用模型来跟踪键状态,然后在键下无效以测试您的组合是否为真:

package
{
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;

    [SWF(percentWidth = 100, percentHeight = 100, backgroundColor = 0xefefef, frameRate = 60)]
    public class X extends Sprite
    {

        private var controlKeyDown:Boolean = false;
        private var altKeyDown:Boolean = false;
        private var shiftKeyDown:Boolean = false;
        private var dKeyDown:Boolean = false;

        public function X()
        {
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
        }

        protected function keyDownHandler(event:KeyboardEvent):void
        {
            switch (event.keyCode)
            {
                case Keyboard.ALTERNATE:
                    altKeyDown = true;
                    break;
                case Keyboard.CONTROL:
                    controlKeyDown = true;
                    break;
                case Keyboard.SHIFT:
                    shiftKeyDown = true;
                    break;
                case Keyboard.D:
                    dKeyDown = true;
                    break;
            }

            invalidateKeyDown();
        }

        protected function keyUpHandler(event:KeyboardEvent):void
        {
            switch (event.keyCode)
            {
                case Keyboard.ALTERNATE:
                    altKeyDown = false;
                    break;
                case Keyboard.CONTROL:
                    controlKeyDown = false;
                    break;
                case Keyboard.SHIFT:
                    shiftKeyDown = false;
                    break;
                case Keyboard.D:
                    dKeyDown = false;
                    break;
            }
        }

        protected function invalidateKeyDown():Boolean
        {
            if (altKeyDown && controlKeyDown && shiftKeyDown && dKeyDown)
            {
                trace("easter egg.");
                return true;
            }

            return false;
        }

    }
}
于 2012-10-12T15:55:32.357 回答