EDIT: This piece of code below is working. Unfortunately, i can’t test those key events in simulator so i made a mistake and sent the wrong apk to phone. Sorry about that.
I am trying this code that is given here: http://developer.coronalabs.com/reference/index/events/key/eventkeyname
However I can’t detect back key event. I tried to print event.keyName but it is not detecting it when i touched the back button on android device.
Can you please help me out? Thanks.
Here is my code:
-- Key listener
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
eventTxt.text = "("..phase.." , " .. keyName ..")"
if(keyName=="back") then
local a=display.newText("hello",100,600,nil,35)
end
-- we handled the event, so return true.
-- for default behavior, return false.
return true
end
-- Add the key callback
Runtime:addEventListener( "key", onKeyEvent );
Production code of a game of mine: