Difference between revisions of "love.keyboard.isDown"

m
(Replace improper example)
Line 20: Line 20:
 
{{param|boolean|anyDown|True if any supplied key is down, false if not.}}
 
{{param|boolean|anyDown|True if any supplied key is down, false if not.}}
 
== Examples ==
 
== Examples ==
=== Quit on hitting escape ===
+
=== Increase a value while a key is held down ===
 
<source lang="lua">
 
<source lang="lua">
function love.keypressed(k)
+
val = 0  -- establish a variable for later use
if k == 'escape' then
+
function love.update(dt)
love.event.push('q') -- quit the game
+
if love.keyboard.isDown("up") then
 +
val = val + dt  -- we will increase the variable by 1 for every second the key is held down
 
end
 
end
 
end
 
end

Revision as of 16:00, 27 September 2011

Checks whether a certain key is down.

Function

Synopsis

down = love.keyboard.isDown( key )

Arguments

KeyConstant key
The key to check.

Returns

boolean down
True if the key is down, false if not.

Function

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

Synopsis

anyDown = love.keyboard.isDown( key1, key2, key3, ... )

Arguments

KeyConstant keyN
A key to check.

Returns

boolean anyDown
True if any supplied key is down, false if not.

Examples

Increase a value while a key is held down

val = 0   -- establish a variable for later use
function love.update(dt)
	if love.keyboard.isDown("up") then
		val = val + dt   -- we will increase the variable by 1 for every second the key is held down
	end	
end

See Also


Other Languages