Difference between revisions of "love.mouse.isDown"

m (Function)
m (Added table variant available since 0.10.2)
 
(3 intermediate revisions by 3 users not shown)
Line 10: Line 10:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|button|The index of a button to check. 1 is the primary mouse button, 2 is the secondary mouse button, etc.}}
+
{{param|number|button|The index of a button to check. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependant.}}
 
{{param|number|...|Additional button numbers to check.}}
 
{{param|number|...|Additional button numbers to check.}}
 +
 +
=== Returns ===
 +
{{param|boolean|down|True if any specified button is down.}}
 +
 +
== Function ==
 +
{{newin|[[0.10.2]]|102|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
down = love.mouse.isDown({ button, ... })
 +
</source>
 +
=== Arguments ===
 +
{{param|table|buttons|Table containing indexes of mouse buttons to check.}}
 +
{{subparam|table|button|The index of a button to check. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependant.}}
 +
{{subparam|number|...|Additional button numbers to check.}}
 +
 
=== Returns ===
 
=== Returns ===
 
{{param|boolean|down|True if any specified button is down.}}
 
{{param|boolean|down|True if any specified button is down.}}
 +
  
 
== Function ==
 
== Function ==
Line 25: Line 41:
 
=== Returns ===
 
=== Returns ===
 
{{param|boolean|down|True if the specified button is down.}}
 
{{param|boolean|down|True if the specified button is down.}}
 +
 
== Function ==
 
== Function ==
 
{{newinoldin|[[0.7.2]]|072|[[0.10.0]]|100|type=variant}}
 
{{newinoldin|[[0.7.2]]|072|[[0.10.0]]|100|type=variant}}
Line 37: Line 54:
  
 
== Example ==
 
== Example ==
=== Increase a value while the right mouse button is held (version [[0.10.0]] and newer) ===
+
=== Increase a value while the right mouse button is held ===
 
<source lang="lua">
 
<source lang="lua">
 
val = 0  -- establish a variable for later use
 
val = 0  -- establish a variable for later use
Line 46: Line 63:
 
end
 
end
 
</source>
 
</source>
=== Increase a value while the right mouse button is held (version [[0.9.2]] and older) ===
+
 
<source lang="lua">
 
val = 0  -- establish a variable for later use
 
function love.update(dt)
 
if love.mouse.isDown("r") then
 
val = val + dt  -- we will increase the variable by 1 for every second the button is held down
 
end
 
end
 
</source>
 
 
== See Also ==
 
== See Also ==
 
* [[MouseConstant|Mouse Constant / buttons]]
 
* [[MouseConstant|Mouse Constant / buttons]]

Latest revision as of 13:08, 7 December 2022

Checks whether a certain mouse button is down.

This function does not detect mouse wheel scrolling; you must use the love.wheelmoved (or love.mousepressed in version 0.9.2 and older) callback for that.

Function

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

Synopsis

down = love.mouse.isDown( button, ... )

Arguments

number button
The index of a button to check. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependant.
number ...
Additional button numbers to check.

Returns

boolean down
True if any specified button is down.

Function

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

Synopsis

down = love.mouse.isDown({ button, ... })

Arguments

table buttons
Table containing indexes of mouse buttons to check.
table button
The index of a button to check. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependant.
number ...
Additional button numbers to check.

Returns

boolean down
True if any specified button is down.


Function

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

Synopsis

down = love.mouse.isDown( button )

Arguments

MouseConstant button
The button to check.

Returns

boolean down
True if the specified button is down.

Function

Available since LÖVE 0.7.2 and removed in LÖVE 0.10.0
This variant is not supported in earlier or later versions.

Synopsis

anyDown = love.mouse.isDown( button1, button2, button3, ... )

Arguments

MouseConstant buttonN
A button to check.

Returns

boolean anyDown
True if any specified button is down, false otherwise.

Example

Increase a value while the right mouse button is held

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

See Also


Other Languages