Navigation Keys - AS3 / Air for Android

:slightly_smiling_face: Hello friends,
How can I use Android “navigation” keys (Search, Menu, Back) without minimizing APP Air?

keycode: 16777234 / 16777238 / 16777247

I think you are looking for “prevent default”, eg:

if (event.keyCode == Keyboard.BACK)
{
	event.preventDefault();
}
2 Likes

Here Is Your Best Code




NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, CheckKeypress, false, 0, true)

function CheckKeypress(event:KeyboardEvent):void 
{ 
    switch (event.keyCode) 
    { 
        case Keyboard.BACK: 
        event.preventDefault();
        gotoAndPlay (1);
        break; 
        case Keyboard.MENU: 
        trace("Menu key is pressed.");
        break; 
        case Keyboard.SEARCH: 
        trace("Search key is pressed."); 
        break; 
        } 
        }
2 Likes

:wink: I will test the codes, and then I’ll come back to tell if it worked correctly (without minimizing or exiting the application).
So far thank you very much for the answers.

1 Like

Hi friends…
The “Back” button worked perfectly, the other two (“Menu” and “Search”) didn’t match, but I believe it is because the newer version of Android no longer uses these keys according to these functions… (“event.preventDefault()” only worked for “Back”), but that already helps me a lot. Thank you all.

PS.: I noticed that for the “Back” to work (become available) the App cannot be published in full screen.

In fullscreen (immersive) mode, the back button should just be hidden. Normally a swipe up from the bottom of the app will reveal the onscreen nav controls and allow the back button to be pressed.

Menu and Search I don’t believe are used anymore, only on very old versions of Android.

1 Like