Author Topic: Android Keycodes for Hardware Buttons (Tip)  (Read 3413 times)

Michael71

  • Member
  • **
  • Posts: 37
  • Karma: +0/-0
  • War... War never changes....
    • View Profile
    • NetGfx
Android Keycodes for Hardware Buttons (Tip)
« on: Mon, May 30, 2011 »
Hello, this is my first post I thought I could contribute to this awesome lib and since I didn't find anything in the forums I thought to post.
So here is the code of how to bind and check for the hardware buttons on mobile android phones.
This assumes you are using the latest Flex SDK or Air 2.6+ and flash 10.1+


in the system/input/Keyboard.as
import :
Code: [Select]
import flash.ui.Keyboard;
add the following vars:
   
      
Code: [Select]
//Mobile
public var MENU:Boolean;
public var BACK:Boolean;
public var SEARCH:Boolean;

add the following lines under "Tab" declaration

               
Code: [Select]
//mobile
addKey("MENU",flash.ui.Keyboard.MENU);
addKey("SEARCH",flash.ui.Keyboard.SEARCH);
addKey("BACK",flash.ui.Keyboard.BACK);

if you want to double check you can enter the following code under handleKeyDown function

   
Code: [Select]
if(FlashEvent.keyCode== flash.ui.Keyboard.MENU)
{trace("MENU: "+FlashEvent.keyCode);FlashEvent.preventDefault();}
else if(FlashEvent.keyCode== flash.ui.Keyboard.SEARCH)
{trace("SEARCH: "+FlashEvent.keyCode);FlashEvent.preventDefault();}
else if(FlashEvent.keyCode== flash.ui.Keyboard.BACK)
{trace("BACK: "+FlashEvent.keyCode);FlashEvent.preventDefault();}

PS: I've searched all over for the HOME button but I can't seem to find it anywhere (it is not the same with pc-keyboard HOME button) if anyone knows the keycode for that please post here.

PS2: The middle joypad button fires under normal "ENTER".

I hope it helps someone...

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: Android Keycodes for Hardware Buttons (Tip)
« Reply #1 on: Tue, May 31, 2011 »
Cool, awesome job!  I'm sure this'll be very useful for those trying for native Android support.
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!

dkwmfkdof

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Android Keycodes for Hardware Buttons (Tip)
« Reply #2 on: Fri, Jan 27, 2012 »
addKey(...)

where is this addKey()
is it custom method ?