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

The Mouse-Events

Started by 3istee, 25 December 2012 - 09:11 AM
3istee #1
Posted 25 December 2012 - 10:11 AM
Hello,
this tutorial shall teach the very basics about the mouse events.

Note: For this tutorial you need to know how os.pullEvent() works and what events are.
If you don't, you can look it up here:

Wiki
Forum post

mouse_click
SpoilerArguments: Left-/Rightclick (1/2), x, y
Triggers whenever someone clicks in the screen.

If it was a leftclick the first argument is 1, else it is 2.
X and y obviously are where the user clicked

Example:
event,arg,x,y = os.pullEvent("mouse_click")
term.setCursorPos(x,y)
write("X")

Example Use: Clickable Button

mouse_drag
SpoilerArguments: Left-/Rightclick (1/2), x, y

Triggers whenever someone clicks and holds a mousebutton in the screen.
Keeps triggering as long as the mouse button is held.

If it was a leftclick the first argument is 1, else it is 2.
X and y are where the user clicked/the mouse was while the button was held down.

Example:
event,arg,x,y = os.pullEvent("mouse_drag")
term.setCursorPos(x,y)
write("X")

Example Use: Painting/Games

mouse_scroll
SpoilerArguments: Up/Down (-1/1), x, y
Triggers whenever someone uses the mousewheel while the mouse is in the screen.

The first argument tells in which direction the user scrolled; -1 is up and 1 is down.
X and y are where the mouse was as the user scrolled.

Example:
event,arg,x,y = os.pullEvent("mouse_scroll")
term.setCursorPos(x,y)
write("X")
term.scroll(arg)

Example Use: Scrolling text ._.
Rwkeith #2
Posted 07 January 2013 - 05:51 AM
Good simple tutorial for starting a GUI.
PixelToast #3
Posted 07 January 2013 - 06:00 AM
more readable than the wiki +1
remiX #4
Posted 08 January 2013 - 01:20 AM
Mouse drag and mouse click have 3 numbers for the first argument, the middle scroll is also triggered if clicked / dragged.
Frederikam #5
Posted 08 January 2013 - 03:12 AM
Sounds simple enough, i'll give it a try at some date.