Difference between revisions of "love.keypressed"
m |
(Added new 0.9.0 variant) |
||
Line 1: | Line 1: | ||
Callback function triggered when a key is pressed. Very useful. | Callback function triggered when a key is pressed. Very useful. | ||
== Function == | == Function == | ||
+ | {{newin|[[0.9.0]]|090|type=variant}} | ||
+ | === Synopsis === | ||
+ | <source lang="lua"> | ||
+ | love.keypressed( key, isrepeat ) | ||
+ | </source> | ||
+ | === Arguments === | ||
+ | {{param|KeyConstant|key|Character of the key pressed.}} | ||
+ | {{param|boolean|isrepeat|Whether this keypress event is a repeat. The delay between key repeats depends on the user's system settings.}} | ||
+ | === Returns === | ||
+ | Nothing. | ||
+ | == Function == | ||
+ | {{oldin|[[0.9.0]]|090|type=variant|text=Unicode text input is now handled separately via [[love.textinput]]}} | ||
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 20: | Line 32: | ||
</source> | </source> | ||
− | Record and print text the user writes. | + | Record and print text the user writes (0.8.0 and below.) |
<source lang="lua"> | <source lang="lua"> | ||
function love.load() | function love.load() |
Revision as of 07:40, 26 August 2013
Callback function triggered when a key is pressed. Very useful.
Contents
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.
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.push.
function love.keypressed(key) -- we do not need the unicode, so we can leave it out
if key == "escape" then
love.event.push("quit") -- actually causes the app to quit
end
end
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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info