Difference between revisions of "Mouse click (event)"

From ComputerCraft Wiki
Jump to: navigation, search
m
(pressing extra mouse buttons are registered as left mouse button)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
{{Event
 
{{Event
 
|name=mouse_click
 
|name=mouse_click
|desc=Fired when the terminal of an advanced system is clicked. Unavailable to normal systems, as these lack mouse support (except via attached [[Advanced Monitor]]s, which grant access to the [[monitor_touch_(event)|monitor_touch event]]).
+
|desc=Fired when the terminal of an advanced system is pressed with a mouse. Unavailable to normal systems, as these lack mouse support.
|return1=The mouse button that was clicked. Left Mouse Button is returned as the number 1, and Right Mouse Button is returned as the number 2
+
|return1=The mouse button that was clicked. Left Mouse Button is returned as the number 1, Right Mouse Button is returned as the number 2 and Middle Mouse Button is returned as the number 3. If you have more than three buttons on your mouse, pressing them will return 1.
 
|return2=The X-coordinate of the click (in screen-characters).
 
|return2=The X-coordinate of the click (in screen-characters).
 
|return3=The Y-coordinate of the click (in screen-characters).
 
|return3=The Y-coordinate of the click (in screen-characters).
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Print the button and the co-ordinates of every mouse click we receive a ''mouse_click'' event.
+
|desc=Print the button and the co-ordinates of every mouse click we receive.
 
|code=
 
|code=
 
  while true do
 
  while true do
   local event, button, xPos, yPos = [[os.pullEvent]]("[[mouse_click_(event)|mouse_click]]")
+
   local event, button, x, y = '''[[os.pullEvent]]( "mouse_click" )'''
   [[print]]("Mouse button clicked: ", button, " => Click Position X: ", xPos, " => Click Position Y: ", yPos)
+
 
 +
   [[print]]( "The mouse button ", button, " was pressed at ", x, " and ", y )
 
  end
 
  end
 
|output=The button that was pressed, followed by the X and Y position of the event.
 
|output=The button that was pressed, followed by the X and Y position of the event.
 
}}
 
}}
 
}}
 
}}

Latest revision as of 16:40, 13 December 2016


Grid Modem.png  Event mouse_click
Fired when the terminal of an advanced system is pressed with a mouse. Unavailable to normal systems, as these lack mouse support.
Returned Object 1 The mouse button that was clicked. Left Mouse Button is returned as the number 1, Right Mouse Button is returned as the number 2 and Middle Mouse Button is returned as the number 3. If you have more than three buttons on your mouse, pressing them will return 1.
Returned Object 2 The X-coordinate of the click (in screen-characters).
Returned Object 3 The Y-coordinate of the click (in screen-characters).

Examples

Grid paper.png  Example
Print the button and the co-ordinates of every mouse click we receive.
Code
while true do
  local event, button, x, y = os.pullEvent( "mouse_click" )
  
  print( "The mouse button ", button, " was pressed at ", x, " and ", y )
end
Output The button that was pressed, followed by the X and Y position of the event.