Callback function triggered when a key is pressed.
Available since LÖVE 0.10.0
This variant is not supported in earlier versions.
love.keypressed( key, scancode, isrepeat )
KeyConstant key
Scancode scancode
boolean isrepeat
Nothing.
Scancodes are keyboard layout-independent, so the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.
Key repeat needs to be enabled with love.keyboard.setKeyRepeat for repeat keypress events to be received. This does not affect love.textinput.
Available since LÖVE 0.9.0 and removed in LÖVE 0.10.0
This variant is not supported in earlier or later versions.
love.keypressed( key, isrepeat )
KeyConstant key
boolean isrepeat
Nothing.
Key repeat needs to be enabled with love.keyboard.setKeyRepeat for repeat keypress events to be received.
Removed in LÖVE 0.9.0
Unicode text input is now handled separately via love.textinput.
love.keypressed( key, unicode )
KeyConstant key
number unicode
Nothing.
Exit the game when the player presses the Escape key, using love.event.quit.
function love.keypressed(key) if key == "escape" then love.event.quit() end end
Removed in LÖVE 0.9.0
Text input is now handled separately via love.textinput..
Record and print text the user writes (0.8.0 and below.)
function love.load() text = "Type away! -- " end function love.keypressed(key, unicode) -- ignore non-printable characters (see http://www.ascii-code.com/) if unicode > 31 and unicode < 127 then text = text .. string.char(unicode) end end function love.draw() love.graphics.printf(text, 0, 0, 800) end
© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.keypressed