function keyPressedOnce(key)
if (keyPressed(key)) then
while (keyPressed(key)) do
coroutine.yield()
end
return true
end
return false
end
However I run into big problems when multiple keys are pressed, as it enters the while loop until the user releases the first detected key. Which is kinda pointless, because when moving your usually pressing forward and the left or right at the same time.
while(true) do
if (keyboardPress(key.VK_W)) then
move_forward = true
else
if (move_forward == true) then
-- save coordinate
move_forward = false
end
end
end
-- Update, must be called at least once right after init
-- Should also be called at the *end* of every update cycle
for i,v in pairs(key) do
keystate[i] = keyPressed(v);
end
Now you can detect key presses or releases easier.
function keyJustPressed(k)
if( keyPressed(k) and not keystate[k] ) then
return true;
end
return false;
end
function keyJustReleased(k)
if( not keyPressed(k) and keystate[k] ) then
return true;
end
return false;
end