Difference between revisions of "Mouse drag (event)"
From ComputerCraft Wiki
m (Updated error with only listing two event parameters, and not three.) |
(Added a graphical code example) |
||
| Line 5: | Line 5: | ||
|desc=Fired when the mouse is dragged (implies that a [[mouse_click_(event)|mouse_click]] event has already occurred). | |desc=Fired when the mouse is dragged (implies that a [[mouse_click_(event)|mouse_click]] event has already occurred). | ||
|return1=The mouse button that was clicked. | |return1=The mouse button that was clicked. | ||
| − | |return2=The X-coordinate of the | + | |return2=The X-coordinate of the mouse (in screen-characters). |
| − | |return3=The Y-coordinate of the | + | |return3=The Y-coordinate of the mouse (in screen-characters). |
|examples= | |examples= | ||
{{Example | {{Example | ||
| Line 13: | Line 13: | ||
while true do | while true do | ||
_, button, xPos, yPos = os.pullEvent("[[mouse_drag_(event)|mouse_drag]]") | _, button, xPos, yPos = os.pullEvent("[[mouse_drag_(event)|mouse_drag]]") | ||
| − | [[print]]("mouse_drag => " .. tostring(button) .. ": " .. | + | [[print]]("mouse_drag => " .. [[tostring]](button) .. ": " .. |
"X: " .. [[tostring]](xPos) .. ", " .. | "X: " .. [[tostring]](xPos) .. ", " .. | ||
"Y: " .. [[tostring]](yPos)) | "Y: " .. [[tostring]](yPos)) | ||
| Line 19: | Line 19: | ||
|output=The X and Y position of the mouse during the drag. | |output=The X and Y position of the mouse during the drag. | ||
}} | }} | ||
| + | {{Example | ||
| + | |desc=Draws a single pixel on the screen, which is moved to the mouse position when mouse is clicked and dragged on the screen | ||
| + | |code= | ||
| + | x = 5 | ||
| + | y = 5 | ||
| + | while true do | ||
| + | [[term.clear]]() | ||
| + | [[term.setBackgroundColor]]( colors.black ) | ||
| + | [[paintutils.drawPixel]]( x, y, colors.red ) | ||
| + | |||
| + | event, button, xPos, yPos = os.pullEvent("[[mouse_drag_(event)|mouse_drag]]") | ||
| + | |||
| + | if button == 1 then -- left button was clicked | ||
| + | x = xPos | ||
| + | y = yPos | ||
| + | end | ||
| + | end | ||
| + | |output= | ||
}} | }} | ||
Revision as of 17:23, 18 January 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 16:00, 30 November 2012 (MSK)) |
{{Event |name=mouse_drag |desc=Fired when the mouse is dragged (implies that a mouse_click event has already occurred). |return1=The mouse button that was clicked. |return2=The X-coordinate of the mouse (in screen-characters). |return3=The Y-coordinate of the mouse (in screen-characters). |examples=
| Print the new co-ordinates of the mouse every time a mouse_drag event occurs. | |
| Code |
while true do
_, button, xPos, yPos = os.pullEvent("mouse_drag")
print("mouse_drag => " .. tostring(button) .. ": " ..
"X: " .. tostring(xPos) .. ", " ..
"Y: " .. tostring(yPos))
end
|
| Output | The X and Y position of the mouse during the drag. |
| Draws a single pixel on the screen, which is moved to the mouse position when mouse is clicked and dragged on the screen | |
| Code |
x = 5 y = 5 while true do term.clear() term.setBackgroundColor( colors.black ) paintutils.drawPixel( x, y, colors.red ) event, button, xPos, yPos = os.pullEvent("mouse_drag") if button == 1 then -- left button was clicked x = xPos y = yPos end end |