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

Mouse events?

Started by TheOddByte, 29 March 2013 - 09:30 AM
TheOddByte #1
Posted 29 March 2013 - 10:30 AM
Well I mainly want to ask here how do you use mouse events?
Like for example how do I detect if I press left or right mouse button etc. ?
Would something like this work?
Or how do you use it?

evt, p1 = os.pullEvent()
    if evt == "mouse_click" and 
  p1 == "right" then
--Do stuff
end
remiX #2
Posted 29 March 2013 - 10:33 AM
When the mouse_click event is fired, it has three parameters:
- button clicked
- x co-ord
- y co-ord

the button clicked can be 1, 2 or 3.
1 being left click
2 being right click
3 being middle click (scroll)


 while true do
	local e = { os.pullEvent() }
	if e[1] == 'mouse_click' then
		local button, x, y = e[2], b[3], b[4]
		if button == 1 then
			-- Left click
		elseif button == 2 then
			-- Right click
		end
	end
 end
 

mouse_drag also has the same three parameters.