2

该类MouseEvent具有 properties altKey,我可以使用它ctrlKey来确定事件发生时是否按下shiftKey了修饰键(即AltCtrlShift )。

但我想确定在 MouseEvent 期间是否按住Space键。我怎样才能做到这一点?

4

1 回答 1

3

正如@Timofei Davydik 所建议的那样,我通过收听KeyboardEvent并设置一个标志来指示所持有的空格键的状态以“手动”方式执行此操作。然后我只是在监听器中使用这个标志的值MouseEvent。代码有点像这样(您可以添加您需要观看的任何其他键):

键盘事件监听器:

public class ModifierKeyboard
{
    /**
     *determine whether space key is held down
     */
    public static var spaceIsHeld:Boolean = false;

    /**
     * this handles the keyDown event on main app
     */
    public static function app_keyDownHandler(event:KeyboardEvent):void
    {
        switch (event.keyCode)
        {
            case Keyboard.SPACE:
                if (!spaceIsHeld)
                {
                    spaceIsHeld = true;
                }
                break;
        }
    }

    /**
     * this handles the keyUp event on main app
     */
    public static function app_keyUpHandler(event:KeyboardEvent):void
    {
        switch (event.keyCode)
        {           
            case Keyboard.SPACE:
                spaceIsHeld = false;
                break;
        }
    }
}
于 2013-11-23T08:40:02.820 回答