MouseEvent
类具有altKey
,ctrlKey
和shiftKey
属性,可用于确定是否有修饰键(即 Alt Ctrl 和 Shift )。
但我想确定在MouseEvent期间是否按下了 Space 键。我怎么能这样做?
答案 0 :(得分:3)
正如@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;
}
}
}