views:

743

answers:

3

I am struggling with an air flex application. Whenever I click ALT+something, vista makes a sound. I suspect that it is connected with non-existing menu bar.

Any ideas how to disable my app responding to shortcuts where alt is involved?

Here's the code:

stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
...
      public function onKeyUp(event:KeyboardEvent):void {
                trace("inside onKeyUp");

                if (event.altKey) {
                 if (event.keyCode == 69 /* E */) {
                  detailsBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true));
                 } else if (event.keyCode == 65 /* A */) {
                  andmevahetusBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true));
                 } else if (event.keyCode == 83 /* S */) {
                  Application.application.close();
        } else {
         trace("Key pressed. keyCode: " + event.keyCode + ", charCode: " + event.charCode);
        }
       }
            }

I tried everything:

event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();

Nothing helped.

A: 

Does the beep happen on key down or on key up?

Samuel
I tried to add a listener for KEY_DOWN as well.
HappyCoder
A: 

Try setting the keycode to 0 in the onkeypress event (if you don't use it afterwards).

Scoregraphic
Unfortunately, I can't. Computer with Flex environment installed is at work.
HappyCoder
+1  A: 

It might be the operating system catching the key press, and responding to it. In which case, attempting to stop the key event inside your application won't matter.

Event processing in Flex/Flash apps does not affect Windows event processing. Stopping keypress propagation in Actionscript can only affect your app, not the operating system.

You could try two things:

  • Find why Windows is beeping due to ALT keypresses (might be because of an international keyboard layout, accessibility options, or who knows what), or
  • Although it doesn't quite fit your design, switch from ALT-X keypresses to CTRL-X keypresses?

Hope this helps!

doihaveto
That's right. Windows (Vista in my case) is listening to ALT + ... If only it was possible to disable even hidden menu bar from flex application for a parent window that gets opened on start (it's possible for child-windows).
HappyCoder