Difference between revisions of "love.keypressed"

m (Undo revision 13574 by Qc514965372 (talk))
m (Examples)
Line 34: Line 34:
 
</source>
 
</source>
  
 +
 +
{{oldin|[[0.9.0]]|090|type=example|text=Text input is now handled separately via love.textinput.}}
 
Record and print text the user writes (0.8.0 and below.)
 
Record and print text the user writes (0.8.0 and below.)
 
<source lang="lua">
 
<source lang="lua">
Line 51: Line 53:
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love]]
 
* [[parent::love]]

Revision as of 23:53, 24 March 2015

Callback function triggered when a key is pressed.

Function

Available since LÖVE 0.9.0
This variant is not supported in earlier versions.

Synopsis

love.keypressed( key, isrepeat )

Arguments

KeyConstant key
Character of the key pressed.
boolean isrepeat
Whether this keypress event is a repeat. The delay between key repeats depends on the user's system settings.

Returns

Nothing.

Notes

Key repeat needs to be enabled with love.keyboard.setKeyRepeat for repeat keypress events to be received.

Function

Removed in LÖVE 0.9.0
Unicode text input is now handled separately via love.textinput.

Synopsis

love.keypressed( key, unicode )

Arguments

KeyConstant key
Character of the key pressed.
number unicode
The unicode number of the key pressed.

Returns

Nothing.

Examples

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

See Also


Other Languages