Difference between revisions of "love.keypressed"

(Add an example)
m (better comments)
Line 11: Line 11:
 
Nothing.
 
Nothing.
 
== Examples ==
 
== Examples ==
Exit the game when the player presses the Escape key.  
+
Exit the game when the player presses the Escape key, using [[love.event.push]].  
 
<source lang="lua">
 
<source lang="lua">
function love.keypressed(key, unicode)
+
function love.keypressed(key)  -- we do not need the unicode, so we can leave it out
 
   if key == "escape" then
 
   if key == "escape" then
       love.event.push('q')
+
       love.event.push("q")   -- actually causes the app to quit
 
   end
 
   end
 
end
 
end

Revision as of 20:33, 26 September 2011

Callback function triggered when a key is pressed.

Function

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("q")   -- actually causes the app to quit
   end
end

See Also


Other Languages