MouseEvent
类具有属性altKey
、ctrlKey
和shiftKey
,我可以用来确定事件发生时是否按住了修饰键(即 Alt、Ctrl 和 Shift)。
但我想确定在鼠标事件期间是否按住空格键。我该怎么做?
正如@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;
}
}
}