How to use Ultimote "hardware keys" feature?

Hi.

I already used successfully Ultimote to send acceletator events to the simulator. However, I am not having the same success with the hardware keys?

Do I need to do something else besides running the app in Debug mode?

Could someone help me and give me the steps-by-steps? [import]uid: 181011 topic_id: 35206 reply_id: 335206[/import]

Hello rsc,

Please try the included Corona SDK Hardware keys example and see if that works. For reference the code is below:

-- Project: KeyEvents  
--  
-- File name: main.lua  
--  
-- Author: Corona Labs  
--  
-- Abstract: Handle navigation key events on Android devices  
--  
-- Demonstrates:   
--  
-- File dependencies: build.settings  
--  
-- Target devices: Android (no Simulator or iOS)  
--  
-- Update History:  
-- 7/14/2011 1.1 Added "volumeUp" exception code / removed splash screen  
-- 7/12/2011 1.0 Initial version  
--  
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license  
-- Copyright (C) 2011 Corona Labs Inc. All Rights Reserved.  
---------------------------------------------------------------------------------------  
  
-- Create text message label  
--  
local title = display.newText( "Press a navigation key", 0, 0, nil, 20 )  
title.x = display.contentWidth/2 -- Center the text  
title.y = 40  
  
local eventTxt = display.newText( "Waiting for nav key event...", 0, 0, nil, 20 )  
eventTxt.x = display.contentWidth/2 -- Center the text  
eventTxt.y = display.contentHeight/2-30  
eventTxt:setTextColor( 255, 255, 255 )  
  
-- Check that we are running on Android device  
--  
if "Android" ~= system.getInfo("platformName") then  
 eventTxt.text = "Build for Android Device!"  
end  
  
-- The Key Event Listener  
--  
local function onKeyEvent( event )  
 local returnValue = true  
  
 local phase = event.phase  
 local keyName = event.keyName  
 eventTxt.text = "("..phase.." , " .. keyName ..")"  
 print( "Listener: " .. event.name )  
  
 -- Make an exception for Volume Up key and default to it's normal function (just for show)  
 if "volumeUp" == keyName then  
 returnValue = false -- use default key operation  
 print( "found 'volumeUp' key" )  
 end  
  
 -- we handled the event, so return true.  
 -- for default behavior, return false.  
 return returnValue  
end  
  
-- Add the key callback  
Runtime:addEventListener( "key", onKeyEvent );  

This is the program we used to test Ultimote hardware key events.

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 35206 reply_id: 139972[/import]

Hi.

I tried using the code that you provided and also the code from Corona Template (I know, they are the same) and it did not work (both in Normal mode and Debug mode). In fact, I modified your code to get accelerometers events and it also did not work.

I made some tests and I found that if I modify your code above by inserting the following lines, the Ultimote hardware keys (and also accelerometer) starts to work.

[lua]local function onFrame()

end

Runtime:addEventListener (“enterFrame”, onFrame)[/lua]

Does this make any sense? As you can see, my event listener function is empty, but the Ultimote only works if I add that enterFrame Listener.

As I said in the first post, I already used the accelerometer with success in the past and I did not remember adding the enterFrame event. I don’t know if this necessity of using the enterFrame appeared in the LuaGlider lastest version…

Well, just to keep your guys aware of this.

And thank you for making the LuaGlider, it is great tool and I use it everyday.
rsc [import]uid: 181011 topic_id: 35206 reply_id: 140119[/import]

@rsc,

Thanks for letting us know. This bug has already been fixed in the development builds and will be fixed when 1.8 comes out.

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 35206 reply_id: 140281[/import]

Hello rsc,

Please try the included Corona SDK Hardware keys example and see if that works. For reference the code is below:

-- Project: KeyEvents  
--  
-- File name: main.lua  
--  
-- Author: Corona Labs  
--  
-- Abstract: Handle navigation key events on Android devices  
--  
-- Demonstrates:   
--  
-- File dependencies: build.settings  
--  
-- Target devices: Android (no Simulator or iOS)  
--  
-- Update History:  
-- 7/14/2011 1.1 Added "volumeUp" exception code / removed splash screen  
-- 7/12/2011 1.0 Initial version  
--  
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license  
-- Copyright (C) 2011 Corona Labs Inc. All Rights Reserved.  
---------------------------------------------------------------------------------------  
  
-- Create text message label  
--  
local title = display.newText( "Press a navigation key", 0, 0, nil, 20 )  
title.x = display.contentWidth/2 -- Center the text  
title.y = 40  
  
local eventTxt = display.newText( "Waiting for nav key event...", 0, 0, nil, 20 )  
eventTxt.x = display.contentWidth/2 -- Center the text  
eventTxt.y = display.contentHeight/2-30  
eventTxt:setTextColor( 255, 255, 255 )  
  
-- Check that we are running on Android device  
--  
if "Android" ~= system.getInfo("platformName") then  
 eventTxt.text = "Build for Android Device!"  
end  
  
-- The Key Event Listener  
--  
local function onKeyEvent( event )  
 local returnValue = true  
  
 local phase = event.phase  
 local keyName = event.keyName  
 eventTxt.text = "("..phase.." , " .. keyName ..")"  
 print( "Listener: " .. event.name )  
  
 -- Make an exception for Volume Up key and default to it's normal function (just for show)  
 if "volumeUp" == keyName then  
 returnValue = false -- use default key operation  
 print( "found 'volumeUp' key" )  
 end  
  
 -- we handled the event, so return true.  
 -- for default behavior, return false.  
 return returnValue  
end  
  
-- Add the key callback  
Runtime:addEventListener( "key", onKeyEvent );  

This is the program we used to test Ultimote hardware key events.

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 35206 reply_id: 139972[/import]

Hi.

I tried using the code that you provided and also the code from Corona Template (I know, they are the same) and it did not work (both in Normal mode and Debug mode). In fact, I modified your code to get accelerometers events and it also did not work.

I made some tests and I found that if I modify your code above by inserting the following lines, the Ultimote hardware keys (and also accelerometer) starts to work.

[lua]local function onFrame()

end

Runtime:addEventListener (“enterFrame”, onFrame)[/lua]

Does this make any sense? As you can see, my event listener function is empty, but the Ultimote only works if I add that enterFrame Listener.

As I said in the first post, I already used the accelerometer with success in the past and I did not remember adding the enterFrame event. I don’t know if this necessity of using the enterFrame appeared in the LuaGlider lastest version…

Well, just to keep your guys aware of this.

And thank you for making the LuaGlider, it is great tool and I use it everyday.
rsc [import]uid: 181011 topic_id: 35206 reply_id: 140119[/import]

@rsc,

Thanks for letting us know. This bug has already been fixed in the development builds and will be fixed when 1.8 comes out.

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 35206 reply_id: 140281[/import]