Hello guys! I’ve been trying to understand pew pew sample project but I found it a bit complex.
Could you please help me out here?
What is the real listener? The one below?
Runtime:addEventListener( “key”, onKeyEvent )
I do have to activate it first?
system.activate(“controllerUserInteraction”)
I have also tried to maintain a .lua controller but I can’t see anything at log screen:
local composer = require( “composer” )
local controller = {}
– Get Input Device Descriptor
local inputDevices = system.getInputDevices();
for i = 1,#inputDevices do
local device = inputDevices[i];
print(device.displayName);
end
– Check the Status of the Input Device
local function onInputDeviceStatusChanged( event )
if ( event.device.isConnected ) then
--if ( event.connectionStateChanged ) then
if ( event.device.isConnected ) then
– Device has been connected
print(event.connectionStateChanged);
print(event.device);
print(event.name);
print(event.reconfigured);
print(“Device is connected”);
else
– Connection has been lost
print(“Device not connected”);
end
end
end
Runtime:addEventListener( “inputDeviceStatus”, onInputDeviceStatusChanged );
– BEGIN COMPOSER SETVARIABLE EXAMPLE
– Handle all Key Events
function onKeyEvent( event )
setDevice( event.device, event.device.displayName );
if (event.phase == “down”) then
keyPos = event.keyName;
print(keyPos);
– assign the keyPos to the Runtime:dispatchEvent Object
Runtime:dispatchEvent( {
name = “controllerKeyPos”,
key = keyPos
} );
end
return keyPos;
end
composer.setVariable( “function_onKeyEvent”, onKeyEvent )
Runtime:addEventListener( “key”, onKeyEvent );
return controller;
– END COMPOSER SETVARIABLE EXAMPLE
I am using a Nimbus controller for testing with my Mac. Whenever I connect it I receive a few lines at debugging screen:
Sep 17 04:21:57.403 true
userdata: 0x60000025d878
inputDeviceStatus
false
Device is connected
Sep 17 04:21:57.423 false
userdata: 0x60000025d878
inputDeviceStatus
true
Device is connected
true
userdata: 0x60000025d878
inputDeviceStatus
false
Device is connected
Thanks!