Difference between revisions of "Mouse click (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(better code example, also better coding habits)
(Clarified the output of return1)
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 mouse button that was clicked. Left Mouse Button is returned as the number 1, and Right Mouse Button is returned as the number 2
 
|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).

Revision as of 16:00, 1 March 2014


Grid Modem.png  Event mouse_click
Fired when the terminal is clicked.
Returned Object 1 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
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 a mouse_click event.
Code
while true do
  local event, button, xPos, yPos = os.pullEvent("mouse_click")
  print("Mouse button clicked: ", button, " => Click Position X: ", xPos, " => Click Position Y: ", yPos)
end
Output The button that was pressed, followed by the X and Y position of the event.