I want to know how to use the mouse_click function in programs.
- How to use it
- What I can use it for
- What it can do
- Example Codes / Tutorials
Thanks, AnthonyD98
local event, button, x, y, = os.pullEvent("mouse_click") -- Catches the mouse_click event
term.setCursorPos(x,y) -- Sets the x, y coordinates to where you clicked
print(" < You clicked here!") -- Prints this string at that location
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
-- it was clicked
end
Also to expand on Zoinky since SO many people don't seem to understand this part. Where Zoinky has
local event, button, x, y = os.pullEvent("mouse_click")
the program will WAIT there UNTIL the user clicks the mouse. It WILL NOT continue running. To have it not do this you would do something like this
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
-- it was clicked
end
doing the above method also allows us to check for multiple events like so
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
-- it was clicked
elseif event == "mouse_drag" then
-- the mouse was dragged
end
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
if button == 1 then -- this is left click, 2 is right click and 3 is middle click
if x == 1 and y == 1 then -- top left corner clicked
-- some 1 pixel button or such
elseif x >= 2 and x <= 5 and y >= 2 and y <= 4 then
-- a larger area
end
end
end
How would I make it do something If it clicked a specific x and y location?
if event == "mouse_click" and x == XPOS and y == YPOS then -- Replace XPOS and YPOS with the location you want.
-- Do stuff
end
Again all on the Wiki and the tutorial pages……..local event, button, x, y = os.pullEvent() if event == "mouse_click" then if button == 1 then -- this is left click, 2 is right click and 3 is middle click if x == 1 and y == 1 then -- top left corner clicked -- some 1 pixel button or such elseif x >= 2 and x <= 5 and y >= 2 and y <= 4 then -- a larger area end end end