Just a random thought on this… Okay, not so random, I did a test… When I press the N button on my Nook Color, two events fire:
D/WindowManager( 958): interceptKeyTi code=4 down=true repeatCount=0 keyguardOn=false mHomePressed=false
I/Corona ( 1378): table: 0x2bf138 {
I/Corona ( 1378): [phase] =\> "down"
I/Corona ( 1378): [name] =\> "key"
I/Corona ( 1378): [keyName] =\> "back"
I/Corona ( 1378): }
D/WindowManager( 958): interceptKeyTi code=4 down=false repeatCount=0 keyguardOn=false mHomePressed=false
I/Corona ( 1378): table: 0x2bf560 {
I/Corona ( 1378): [phase] =\> "up"
I/Corona ( 1378): [name] =\> "key"
I/Corona ( 1378): [keyName] =\> "back"
I/Corona ( 1378): }
Much like a touch handler where you have a began phase and an ended phase, your event handler fires twice. Your code:
// Set up a listener for the NOOK button
local function onNookPress( event )
local phase = event.phase
local keyName = event.keyName
if keyName == "back" then
-- Do stuff
-- Keep the return true line here because
-- you want to successfully return
return true
end
end
-- Attach the listener to the Runtime object
Runtime:addEventListener( "key", onNookPress)
Your event handler is going to run twice, so whatever you’re doing inside that if is going to happen twice. Also, the “return true” probably should be outside the if statement. I would do something more like:
[code]
local function keyListener(event)
utility.print_r(event)
if event.phase == “up” and event.keyName == “back” then
–do stuff like:
–if storyboard.storyboard.getCurrentSceneName() == “menu” then
– native.requestExit()
–else
– storyboard.gotoScene(storyboard.getPrevious())
–end
end
return true
end
Runtime:addEventListener( “key”, keyListener )
[/code] [import]uid: 199310 topic_id: 34520 reply_id: 137804[/import]