Mouse scroll (event)
From ComputerCraft Wiki
Examples
Example | |
Prints the direction and the co-ordinates of every mouse scroll we receive a mouse_scroll event for. | |
Code |
while true do local event, scrollDirection, x, y = os.pullEvent("mouse_scroll") print("mouse_scroll: " .. tostring(scrollDirection) .. ", " .. "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. |
Example | |
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 |
local i = 0 while true do term.clear() local _, srollDirection, x, y = os.pullEvent("mouse_scroll") if scrollDirection == -1 then i = i + 1 elseif scrollDirection == 1 then i = i - 1 end term.setCursorPos(x, y) term.write(i) end |
Output | At the coordinates of the scroll, the counter value i is printed. |