Accessing System keys in AIR for Android


/ Published in: ActionScript 3
Save to your folder(s)

As an added bonus you also have access to the keys on your device. Most devices have an HOME, MENU and SEARCH button on the device itself. Of course you can access them. Add an normal key down listener to the stage and respond to it.


Copy this code and paste it in your HTML
  1. stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  2.  
  3.  
  4. private function onKeyDown(event:KeyboardEvent):void
  5. {
  6. if (event.keyCode == Keyboard.BACK) {
  7. event.preventDefault();
  8. log.appendText("Back Pressed\n");
  9. }
  10. else if (event.keyCode == Keyboard.MENU) {
  11. event.preventDefault();
  12. log.appendText("Menu Pressed\n");
  13. }
  14. else if (event.keyCode == Keyboard.SEARCH) {
  15. event.preventDefault();
  16. log.appendText("Search Pressed\n");
  17. }
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.