Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

getKeysPressed

.getKeysPressed()

Returns an Array containing each of the keys that were pressed, on this frame. Each of these keys are a String, naming the key that has been pressed.

It will not include any keys which were pressed on previous frames, even if they are still down.

// Vertically lists keys pressed,
// as they are hit.
y = 10
inc = 32

onEachFrame() do |delta|
    // a low alpha, so values fade out from previous frames
    fill( :black, delta/20.0 )
    
    getControls().getKeysPressed().each() do |key|
        fillText( key, 10, y, :left, :top )
        y = (y + inc) % getScreenHeight()
    end
end

See Also