Difference between revisions of "love.keyboard.isScancodeDown"

m
(Standard WASD or arrow keys for movement)
 
(4 intermediate revisions by 3 users not shown)
Line 14: Line 14:
 
=== Returns ===
 
=== Returns ===
 
{{param|boolean|down|True if any supplied Scancode is down, false if not.}}
 
{{param|boolean|down|True if any supplied Scancode is down, false if not.}}
 +
 +
== Function ==
 +
{{newin|[[0.10.2]]|102|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
down = love.keyboard.isScancodeDown({ scancode, ... })
 +
</source>
 +
=== Arguments ===
 +
{{param|table|scancodes|Table of Scancodes to check.}}
 +
{{subparam|Scancode|scancode|A Scancode to check.}}
 +
{{subparam|Scancode|...|Additional Scancodes to check.}}
 +
=== Returns ===
 +
{{param|boolean|down|True if any supplied Scancode is down, false if not.}}
 +
 +
== Examples ==
 +
 +
=== Standard WASD or arrow keys for movement ===
 +
<source lang="lua">
 +
function love.update(dt)
 +
local up    = love.keyboard.isScancodeDown('w', 'up')
 +
local down  = love.keyboard.isScancodeDown('s', 'down')
 +
local left  = love.keyboard.isScancodeDown('a', 'left')
 +
local right = love.keyboard.isScancodeDown('d', 'right')
 +
end
 +
</source>
 +
 +
Or
 +
<source lang="lua">
 +
function love.update(dt)
 +
local speed = 100
 +
local dx, dy = 0,0
 +
local isScancodeDown = love.keyboard.isScancodeDown
 +
if isScancodeDown ('a') then dx = dx - dt*speed end
 +
if isScancodeDown ('d') then dx = dx + dt*speed end
 +
if isScancodeDown ('w') then dy = dy - dt*speed end
 +
if isScancodeDown ('s') then dy = dy + dt*speed end
 +
end
 +
</source>
  
 
== See Also ==
 
== See Also ==

Latest revision as of 09:39, 8 January 2024

Available since LÖVE 0.10.0
This function is not supported in earlier versions.

Checks whether the specified Scancodes are pressed. Not to be confused with love.keypressed or love.keyreleased.

Unlike regular KeyConstants, Scancodes are keyboard layout-independent. The scancode "w" is used if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.

Function

Synopsis

down = love.keyboard.isScancodeDown( scancode, ... )

Arguments

Scancode scancode
A Scancode to check.
Scancode ...
Additional Scancodes to check.

Returns

boolean down
True if any supplied Scancode is down, false if not.

Function

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

Synopsis

down = love.keyboard.isScancodeDown({ scancode, ... })

Arguments

table scancodes
Table of Scancodes to check.
Scancode scancode
A Scancode to check.
Scancode ...
Additional Scancodes to check.

Returns

boolean down
True if any supplied Scancode is down, false if not.

Examples

Standard WASD or arrow keys for movement

function love.update(dt)
	local up    = love.keyboard.isScancodeDown('w', 'up')
	local down  = love.keyboard.isScancodeDown('s', 'down')
	local left  = love.keyboard.isScancodeDown('a', 'left')
	local right = love.keyboard.isScancodeDown('d', 'right')
end

Or

function love.update(dt)
	local speed = 100
	local dx, dy = 0,0
	local isScancodeDown = love.keyboard.isScancodeDown
	if isScancodeDown ('a') then dx = dx - dt*speed end
	if isScancodeDown ('d') then dx = dx + dt*speed end
	if isScancodeDown ('w') then dy = dy - dt*speed end
	if isScancodeDown ('s') then dy = dy + dt*speed end
end

See Also

Other Languages