MouseEvent
类具有属性 altKey
、ctrlKey
和 shiftKey
,我可以使用它们来确定是否事件发生时按住了修饰键(即 Alt、Ctrl 和 Shift)。
但我想确定在 MouseEvent 期间是否按住了 Space 键。我怎样才能做到这一点?
最佳答案
正如@Timofei Davydik 所建议的,我通过监听KeyboardEvent
并设置一个标志来指示所按住的空格键的状态,以“手动”方式执行此操作。然后我只需在 MouseEvent
的监听器中使用此标志的值。代码有点像这样(您可以添加您需要观看的任何其他键):
KeyboardEvent 监听器:
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;
}
}
}
关于actionscript-3 - 弹性 : Determine if Space key is held down during MouseEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784759/