Difference between revisions of "Mouse scroll (event)"
From ComputerCraft Wiki
(Added example.) |
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.) |
||
Line 4: | Line 4: | ||
|name=mouse_scroll | |name=mouse_scroll | ||
|desc=Fired when a mousewheel is scrolled in the terminal | |desc=Fired when a mousewheel is scrolled in the terminal | ||
− | |return1=The direction of the mouse-scroll (<var>-1</var> = up, <var>1</var> = down). | + | |return1=The name of the event. |
− | | | + | |return2=The direction of the mouse-scroll (<var>-1</var> = up, <var>1</var> = down). |
− | | | + | |return3=The X-coordinate of the scroll (in screen-characters). |
+ | |return4=The Y-coordinate of the scroll (in screen-characters). | ||
|examples= | |examples= | ||
{{Example | {{Example | ||
Line 12: | Line 13: | ||
|code= | |code= | ||
while true do | while true do | ||
− | + | _, dir, x, y = os.pullEvent("[[mouse_scroll_(event)|mouse_scroll]]") | |
− | [[print]]("mouse_scroll: " .. [[tostring]]( | + | [[print]]("mouse_scroll: " .. [[tostring]](dir) .. ", " .. |
− | "X: " .. [[tostring]]( | + | "X: " .. [[tostring]](x) .. ", " .. |
− | "Y: " .. [[tostring]]( | + | "Y: " .. [[tostring]](y)) |
end | end | ||
|output=The direction the mouse-wheel was scrolled in, followed by the X and Y position of the event. | |output=The direction the mouse-wheel was scrolled in, followed by the X and Y position of the event. | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=A variable, i, keeps track of the relative value of the scroll: every time a mouse-scroll occurs, the code checks the direction, incrementing the variable by one for every scroll up and decrementing the variable by one for every scroll down. | ||
+ | |code= | ||
+ | i = 0 | ||
+ | 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) | ||
+ | |output=At the coordinates of the scroll, the counter value is printed. | ||
}} | }} | ||
}} | }} |
Revision as of 08:27, 4 May 2013
This page needs some serious TLC, stat! Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 15:57, 30 November 2012 (MSK)) |
Examples
Example | |
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. |