Difference between revisions of "love.keyboard.setKeyRepeat"

m (Examples: Fixed arguments of love.keypressed (scancode parameter added))
 
(15 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
Enables or disables key repeat for [[love.keypressed]]. It is disabled by default.
 +
== Function ==
 +
{{newin|[[0.9.0]]|090|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.keyboard.setKeyRepeat( enable )
 +
</source>
 +
=== Arguments ===
 +
{{param|boolean|enable|Whether repeat keypress events should be enabled when a key is held down.}}
 +
=== Returns ===
 +
Nothing.
 +
=== Notes ===
 +
The interval between repeats depends on the user's system settings. This function doesn't affect whether [[love.textinput]] is called multiple times while a key is held down.
 +
 +
== Function ==
 +
{{oldin|[[0.9.0]]|090|type=variant}}
 
Enables key repeating and sets the delay and interval.
 
Enables key repeating and sets the delay and interval.
== Function ==
 
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.keyboard.setKeyRepeat( delay, Interval )
+
love.keyboard.setKeyRepeat( delay, interval )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|delay|The amount of time before repeating the key (in milliseconds). 0 disables key repeat.}}
+
{{param|number|delay|The amount of time before repeating the key (in seconds). 0 disables key repeat.}}
{{param|number|Interval|The amount of time between repeats (in milliseconds)}}
+
{{param|number|interval|The amount of time between repeats (in seconds)}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
 
== Examples ==
 
== Examples ==
=== Press key to continue moving left or right ===
+
Hold left or right to change the position.
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()
require("AnAL.lua")
+
love.keyboard.setKeyRepeat(true)
  -- Load the animation source.
+
x = 50
imgl = love.graphics.newImage("walkl.png")
 
imgr = love.graphics.newImage("walkr.png")
 
imgsl = love.graphics.newImage("stopl.png")
 
imgsr = love.graphics.newImage("stopr.png")
 
  -- Create animation.
 
 
 
  anim = newAnimation(imgsl, 32, 48, 0.1, 0)
 
  animX = 100
 
  animY = 100
 
  --  Interval value = Animation's Delay time * The number of Animation's frame
 
  -- 100 ms * 2 frame = 200 ms (Interval)
 
  love.keyboard.setKeyRepeat(10, 200)
 
 
end
 
end
  
function love.update(dt)
+
function love.keypressed(key, scancode, isrepeat)
  -- Updates the animation. (Enables frame changes)
+
if key == "right" then
  anim:update(dt)
+
x = (x + 80) % love.graphics.getWidth()
 +
elseif key == "left" then
 +
x = (x - 80) % love.graphics.getWidth()
 +
end
 
end
 
end
  
 
function love.draw()
 
function love.draw()
  -- Draw the animation at (100, 100).
+
love.graphics.circle("fill", x, 100, 50, 50)
  anim:draw(animX , animY)
 
 
end
 
end
 +
</source>
  
function love.keypressed(key,unicode)
 
if key == "left" then
 
anim = newAnimation(imgl,32,48,0.1,0)
 
anim:setMode ("once")
 
animX = animX - 10
 
elseif key == "right" then
 
anim = newAnimation(imgr, 32, 48, 0.1, 0)
 
animX = animX + 10
 
anim:setMode ("once")
 
end
 
end
 
</source>
 
 
== See Also ==
 
== See Also ==
 
* [[parent::love.keyboard]]
 
* [[parent::love.keyboard]]
 +
* [[love.keyboard.hasKeyRepeat]]
 +
* [[love.keypressed]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Enables key repeating and sets the delay and interval.}}
+
{{#set:Description=Enables or disables key repeat for [[love.keypressed]].}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.keyboard.setKeyRepeat}}
 
{{i18n|love.keyboard.setKeyRepeat}}

Latest revision as of 09:46, 16 April 2020

Enables or disables key repeat for love.keypressed. It is disabled by default.

Function

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

Synopsis

love.keyboard.setKeyRepeat( enable )

Arguments

boolean enable
Whether repeat keypress events should be enabled when a key is held down.

Returns

Nothing.

Notes

The interval between repeats depends on the user's system settings. This function doesn't affect whether love.textinput is called multiple times while a key is held down.

Function

Removed in LÖVE 0.9.0
This variant is not supported in that and later versions.

Enables key repeating and sets the delay and interval.

Synopsis

love.keyboard.setKeyRepeat( delay, interval )

Arguments

number delay
The amount of time before repeating the key (in seconds). 0 disables key repeat.
number interval
The amount of time between repeats (in seconds)

Returns

Nothing.

Examples

Hold left or right to change the position.

function love.load()
	love.keyboard.setKeyRepeat(true)
	x = 50
end

function love.keypressed(key, scancode, isrepeat)
	if key == "right" then
		x = (x + 80) % love.graphics.getWidth()
	elseif key == "left" then
		x = (x - 80) % love.graphics.getWidth()
	end
end

function love.draw()
	love.graphics.circle("fill", x, 100, 50, 50)
end

See Also


Other Languages