Jump to content




Mouse events?


  • You cannot reply to this topic
1 reply to this topic

#1 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

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


#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users