问题
I have defined a keyboard shortcut that uses space. After I have pressed the shortcut two things happen: some random navigation in my app and also the code in my eventHandler from the keyboard shortcut.
I found THIS table with browser keyboard shortcuts and obviously space sometimes is used for navigation. So is there a way to stop the navigation with space in Flex, because eating the spacebar button doesn't seem to work:
FlexGlobals.topLevelApplication.addEventListener(KeyboardEvent.KEY_DOWN,
ignoreSpaceNavigation);
private static function ignoreSpaceNavigation(event:KeyboardEvent):
event.preventDefault();
event.stopImmediatePropagation();
}
So any ideas how to stop the navigation? (I really want to use space for that keyboard shortcut!)
回答1:
Try to set event listener on a stage and use capture
stage.addEventListener(KeyboardEvent.KEY_DOWN, ignoreSpaceNavigation, true);
来源:https://stackoverflow.com/questions/24205150/how-to-disable-default-browser-navigation-with-space-in-flex