Callback
keypressed( key )
Synopsis
function keypressed( key ) ... end
Arguments
key The key code of the pressed key.
Returns
(Nothing)
Examples
Example 53: Keyboard callbacks
  1. -- Example: Keyboard callbacks 
  2.  
  3. -- Keypressed: Called whenever a key was pressed. 
  4. function keypressed(key) 
  5.    -- I don't want to register spaces. 
  6.    if key ~= love.key_space then 
  7.       lastkey = key .. " pressed" 
  8.    end 
  9. end 
  10.  
  11. -- Keyreleased: Called whenever a key was released. 
  12. function mousereleased(key) 
  13.    -- I don't want to register spaces. 
  14.    if key ~= love.key_space then 
  15.       lastkey = key .. " released" 
  16.    end 
  17. end 
  18.  
  19.  
  20. -- Load a font and set the text variable. 
  21. function load() 
  22.    love.graphics.setFont(love.graphics.newFont(love.default_font, 12)) 
  23.    lastkey = "nothing" 
  24. end 
  25.  
  26. -- Output the last mouse button which was pressed/released. 
  27. function draw() 
  28.    love.graphics.draw("Last key: " .. lastkey, 100100
  29. end 
Copyright © 2006-2008 LÖVE Development Team.