如何在 Flex 中使用 Space 禁用默认浏览器导航

如何在 Flex 中使用 Space 禁用默认浏览器导航

问题描述:

我定义了一个使用空格的键盘快捷键.按下快捷方式后,会发生两件事:我的应用程序中的一些随机导航以及来自键盘快捷方式的 eventHandler 中的代码.

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.

我发现这个表格带有浏览器键盘快捷键,显然有时会使用空格进行导航.那么有没有办法在 Flex 中用空格停止导航,因为吃空格键按钮似乎不起作用:

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!)

尝试在舞台上设置事件监听器并使用捕获

Try to set event listener on a stage and use capture

stage.addEventListener(KeyboardEvent.KEY_DOWN, ignoreSpaceNavigation, true);