This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
NOTUSEDPLEASEDELETE's profile picture

Mouse Tutorial

Started by NOTUSEDPLEASEDELETE, 15 July 2013 - 02:43 PM
NOTUSEDPLEASEDELETE #1
Posted 15 July 2013 - 04:43 PM
This tutorial was created to make the mouse clicks in programs easier.

So first you put the variables in:

event, button, x, y = os.pullEvent("mouse_click")
And now I'll tell you what each one does:
button: Returns left, middle or right depending on what button you pressed.
x: The x in screen characters of your mouse click.
y: The y in screen characters of your mouse click.
So now let's use them:

if x == 1 and y == 1 then
print("You clicked in the top left corner!")
end
So the completed script is:

button, x, y = os.pullEvent("mouse_click")
if x == 1 and y == 1 then
print("You pressed on a monitr ajacent  in the top left corner!")
end
You can also do monitor presses like this:
So first you put the variables in:

event, side, x, y = os.pullEvent("monitor_press")
And now I'll tell you what each one does:
side: What side of the the monitor the press was on.
x: The x in screen characters of your mouse click.
y: The y in screen characters of your mouse click.
So now let's use them:

if x == 1 and y == 1 then
print("You pressed on a monitor adjacent to the computer in the top left corner!")
end
So the completed script is:

button, x, y = os.pullEvent("mouse_click")
if x == 1 and y == 1 then
print("You pressed on a monitor adjacent to the computer in the top left corner!")
end
Kingdaro #2
Posted 15 July 2013 - 07:30 PM
It's a good start, but a little more in-depth content would be good.
Bubba #3
Posted 15 July 2013 - 07:47 PM
When you pull an event, it returns the event name too, so the above code would not work.

e.g. You have:

button, x, y = os.pullEvent("mouse_click")

It should be:

event_type, button, x, y = os.pullEvent("mouse_click")
thegreatstudio #4
Posted 17 July 2013 - 11:04 AM
it should be

local event, button, X, Y = os.pullEventRaw("mouse_click")
if event == "mouse_click" then
if X >= 1 and X <= 10 and Y == 1 and button == 1 then
print("YOLO")
end
end

There!
Zudo #5
Posted 17 July 2013 - 02:11 PM
it should be

local event, button, X, Y = os.pullEventRaw("mouse_click")
if event == "mouse_click" then
if X >= 1 and X <= 10 and Y == 1 and button == 1 then
print("YOLO")
end
end

There!

What, YOLO?
Bubba #6
Posted 17 July 2013 - 02:33 PM
it should be

local event, button, X, Y = os.pullEventRaw("mouse_click")
if event == "mouse_click" then
if X >= 1 and X <= 10 and Y == 1 and button == 1 then
print("YOLO")
end
end

There!

You should never use os.pullEventRaw unless it is necessary. It prevents termination which, unless needed for security, is a bad thing.
NOTUSEDPLEASEDELETE #7
Posted 24 July 2013 - 03:25 AM
Fixed the event return. Now it should work.
NOTUSEDPLEASEDELETE #8
Posted 30 July 2013 - 03:56 AM
Poll Answer:
Mouse dragging(4 votes [66.67%])
Mouse scrolling (2 votes [33.33%])
Mouse Dragging is Coming!
AngryTubersLP #9
Posted 27 August 2013 - 07:59 AM
its realy easy!