How to keep focused after 'alt' was pressed?(Adobe AIR app)
Asked Answered
P

2

9

I was making an application with AIR + Flex.

One Feature is like:

  • When Alt key is down, the mouse cursor changes to B,
  • When Alt key is up, the mouse cursor restores to A.

But the problem is that everytime a release Alt key, the mouse cursor will change back to system default (Arrow shape), and seems like the focus is on somewhere outside the stage.

That reminds me that, when Alt was pressed in a ordinary window, the menu-bar will be focused.

How can I stop this default behavior ?

p.s. I have tried the following ways and doesn`t work:

  • 1) listen to stage's KEY_DOWN/ KEY_UP event, and add event.stopImmediatePropagation() in the event handlers
  • 2) listen to stage's KEY_DOWN/ KEY_UP event, and add event.preventDefault() in the event handlers
  • 3) listen to stage's KEY_DOWN/ KEY_UP event, and add this.setFocus() in the event handlers. And callLater(this.setFocus) doesn't work too.
Pristine answered 18/1, 2011 at 8:58 Comment(6)
Hi Vergil, I did some testing myself and ended basically at the same point you described above, my event handlers are fired but stopping the propagation of the event or attempting to prevent the default behavior produces the same results. From looking at the Docs it appears the altKey is only supported in Windows for the events I was checking out as well so this may be an issue when it comes time to test across platforms, for that reason I suggest using some other modifier key or other keystroke.Hypnos
I also just stumbled on this in the documentation which may lead to an answer but haven't seen any menu's that describe the one shown when the alt key is pressed: livedocs.adobe.com/flex/3/html/help.html?content=Menus_2.htmlHypnos
This may also lead closer to an answer to the problem as presented: adobe.com/devnet/air/flex/quickstart/articles/… although this is discussing creating Chromeless windows it also has some info on how to block default behaviors in NativeWindows.Hypnos
I would avoid ALT for a variety of reasons. Use SHIFT or some other key!Istle
How about systemManager.stage.focus = this; where this is the application.Dode
I use fscommand("trapallkeys", "true"); to stop the ESC key in browser in fullscreen but it doesn't work for ALTDivorcee
E
0

On win impossible. But U can write shell/bash script for activating your app and run it from AIR. See NativeProcess class.

Eurydice answered 7/2, 2012 at 21:44 Comment(0)
O
0

Listen to deactivate event And then do activate

Oliphant answered 1/9, 2014 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.