Difference between revisions of "Mouse scroll (event)"
From ComputerCraft Wiki
TheCoryKid (Talk | contribs) (The description and code example were both wrong. Fixed the return values, changed the example to reflect this, and added a second example.) |
TheCoryKid (Talk | contribs) m (Removed the NeedsWork and fixed my own error.) |
||
| Line 1: | Line 1: | ||
| − | |||
| − | |||
{{Event | {{Event | ||
|name=mouse_scroll | |name=mouse_scroll | ||
| Line 25: | Line 23: | ||
i = 0 | i = 0 | ||
while true do | while true do | ||
| − | + | term.clear() | |
| − | + | _, dir, x, y = os.pullEvent("[[mouse_scroll_(event)|mouse_scroll]]") | |
| − | + | if dir == -1 then | |
| − | + | i = i + 1 | |
| − | + | elseif dir == 1 then | |
| − | + | i = i - 1 | |
| − | + | end | |
| − | + | term.setCursorPos(x, y) | |
| − | + | term.write(i) | |
| + | end | ||
|output=At the coordinates of the scroll, the counter value is printed. | |output=At the coordinates of the scroll, the counter value is printed. | ||
}} | }} | ||
}} | }} | ||
Revision as of 08:29, 4 May 2013
Examples
| Print the direction and the co-ordinates of every mouse scroll we receive a mouse_scroll event for. | |
| Code |
while true do
_, dir, x, y = os.pullEvent("mouse_scroll")
print("mouse_scroll: " .. tostring(dir) .. ", " ..
"X: " .. tostring(x) .. ", " ..
"Y: " .. tostring(y))
end
|
| Output | The direction the mouse-wheel was scrolled in, followed by the X and Y position of the event. |