Difference between revisions of "love.mousepressed"

m
(See Also)
 
(12 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
Callback function triggered when a mouse button is pressed.
 
Callback function triggered when a mouse button is pressed.
 
== Function ==
 
== Function ==
{{newin|[[0.10.0]]|100|type=variant}}
 
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.mousepressed( x, y, button, istouch )
+
love.mousepressed( x, y, button, istouch, presses )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
 
{{param|number|x|Mouse x position, in pixels.}}
 
{{param|number|x|Mouse x position, in pixels.}}
 
{{param|number|y|Mouse y position, in pixels.}}
 
{{param|number|y|Mouse y position, in pixels.}}
{{param|number|button|The button index that was pressed. 1 is the primary button (usually left-click), 2 is the secondary button, etc.}}
+
{{param|number|button|The button index that was pressed. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependent.}}
 
{{param|boolean|istouch|True if the mouse button press originated from a touchscreen touch-press.}}
 
{{param|boolean|istouch|True if the mouse button press originated from a touchscreen touch-press.}}
 +
{{New feature|11.0|
 +
{{param|number|presses|The number of presses in a short time frame and small area, used to simulate double, triple clicks}}
 +
|110}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 29: Line 31:
 
Nothing.
 
Nothing.
 
== Examples ==
 
== Examples ==
Position a string ("Text") wherever the user left-clicks (version [[0.10.0]].)
+
Position a string ("Text") wherever the user left-clicks.
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()
Line 41: Line 43:
  
 
function love.mousepressed(x, y, button, istouch)
 
function love.mousepressed(x, y, button, istouch)
   if button == 1 then -- the primary button
+
   if button == 1 then -- Versions prior to 0.10.0 use the MouseConstant 'l'
      printx = x
 
      printy = y
 
  end
 
end
 
</source>
 
----
 
Position a string ("Text") wherever the user left-clicks (version [[0.9.2]] and older.)
 
<source lang="lua">
 
function love.load()
 
  printx = 0
 
  printy = 0
 
end
 
 
 
function love.draw()
 
  love.graphics.print("Text", printx, printy)
 
end
 
 
 
function love.mousepressed(x, y, button)
 
  if button == "l" then -- this is the lowercase letter L, not a one (1)
 
 
       printx = x
 
       printx = x
 
       printy = y
 
       printy = y
Line 69: Line 52:
 
== See Also ==
 
== See Also ==
 
* [[parent::love]]
 
* [[parent::love]]
 +
* [[love.mouse]]
 +
* [[love.mousemoved]]
 +
* [[love.mousereleased]]
 +
* [[love.mouse.isDown]]
 
[[Category:Callbacks]]
 
[[Category:Callbacks]]
 
{{#set:Description=Callback function triggered when a mouse button is pressed.}}
 
{{#set:Description=Callback function triggered when a mouse button is pressed.}}
{{#set:Subcategory=General}}
+
{{#set:Subcategory=Mouse}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.mousepressed}}
 
{{i18n|love.mousepressed}}

Latest revision as of 07:47, 8 March 2023

Callback function triggered when a mouse button is pressed.

Function

Synopsis

love.mousepressed( x, y, button, istouch, presses )

Arguments

number x
Mouse x position, in pixels.
number y
Mouse y position, in pixels.
number button
The button index that was pressed. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependent.
boolean istouch
True if the mouse button press originated from a touchscreen touch-press.
Available since LÖVE 11.0
number presses
The number of presses in a short time frame and small area, used to simulate double, triple clicks

Returns

Nothing.

Notes

Use love.wheelmoved to detect mouse wheel motion. It will not register as a button press in version 0.10.0 and newer.

Function

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

Synopsis

love.mousepressed( x, y, button )

Arguments

number x
Mouse x position.
number y
Mouse y position.
MouseConstant button
Mouse button pressed.

Returns

Nothing.

Examples

Position a string ("Text") wherever the user left-clicks.

function love.load()
   printx = 0
   printy = 0
end

function love.draw()
   love.graphics.print("Text", printx, printy)
end

function love.mousepressed(x, y, button, istouch)
   if button == 1 then -- Versions prior to 0.10.0 use the MouseConstant 'l'
      printx = x
      printy = y
   end
end

See Also



Other Languages