Difference between revisions of "Mouse click (event)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Corrected mistake where I forgot to pullEvent("mouse_click"). Hurr.)
(Fixed that for ya)
Line 2: Line 2:
 
|name=mouse_click
 
|name=mouse_click
 
|desc=Fired when the terminal is clicked.
 
|desc=Fired when the terminal is clicked.
|return1=The mouse button that was clicked.
+
|return1=The event name.
|return2=The X-coordinate of the click (in screen-characters).
+
|return2=The mouse button that was clicked.
|return3=The Y-coordinate of the click (in screen-characters).
+
|return3=The X-coordinate of the click (in screen-characters).
 +
|return4=The Y-coordinate of the click (in screen-characters).
 
|examples=
 
|examples=
 
{{Example
 
{{Example
Line 10: Line 11:
 
|code=
 
|code=
 
  while true do
 
  while true do
   button, xPos, yPos = os.pullEvent("[[mouse_click_(event)|mouse_click]]")
+
   event, button, xPos, yPos = os.pullEvent("[[mouse_click_(event)|mouse_click]]")
   [[print]]("mouse_click: " .. [[tostring]](button) .. ", " ..
+
   [[print]](e..": " .. [[tostring]](button) .. ", " ..
 
     "X: " .. [[tostring]](xPos) .. ", " ..
 
     "X: " .. [[tostring]](xPos) .. ", " ..
 
     "Y: " .. [[tostring]](yPos))
 
     "Y: " .. [[tostring]](yPos))

Revision as of 09:20, 7 December 2012

Grid Modem.png  Event mouse_click
Fired when the terminal is clicked.
Returned Object 1 The event name.
Returned Object 2 The mouse button that was clicked.
Returned Object 3 The X-coordinate of the click (in screen-characters).
Returned Object 4 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 a mouse_click event.
Code
while true do
  event, button, xPos, yPos = os.pullEvent("mouse_click")
  print(e..": " .. tostring(button) .. ", " ..
    "X: " .. tostring(xPos) .. ", " ..
    "Y: " .. tostring(yPos))
end
Output The button that was pressed, followed by the X and Y position of the event.