onKeyEvent problem

Hi

I have a code here

local function onKeyEvent( event ) if event.nativeKeyCode == 65 then -- A ship.rotation = ship.rotation - 3 end if event.nativeKeyCode == 68 then -- D ship.rotation = ship.rotation + 3 end if event.nativeKeyCode == 87 then -- W ship.y = ship.y - 30 end if event.nativeKeyCode == 83 then -- S ship.y = ship.y + 3 end return false end

I’m using W A S D buttons, to move something, but I have to press the buttons in every single movement. How can I move something with constant pressure?

The events are only generated once per action (keypress and keyup).  This is true for all Corona Key, touch, and controller events.  You only get new events when something has changed.

You have to check to see if the event.phase is “up” or “down”. If it’s down, set a flag that you should move.  When it’s up clear the flag.

Then you need a Runtime:addEventListener(“enterFrame”, somefunction)  where somefunction is code that check to see if your flag to move is set or not and to do your movement there.

Rob

Ok ty

The events are only generated once per action (keypress and keyup).  This is true for all Corona Key, touch, and controller events.  You only get new events when something has changed.

You have to check to see if the event.phase is “up” or “down”. If it’s down, set a flag that you should move.  When it’s up clear the flag.

Then you need a Runtime:addEventListener(“enterFrame”, somefunction)  where somefunction is code that check to see if your flag to move is set or not and to do your movement there.

Rob

Ok ty