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

Touchscreen Monitors

Started by 1vannn, 21 May 2013 - 04:40 PM
1vannn #1
Posted 21 May 2013 - 06:40 PM
How can I use the advanced monitors?

event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
  if x >= 5 and x <= 1 and y <= 1 and y >= 5 then
    print("hi")
  else
    print("no")
  end
end
W00dyR #2
Posted 21 May 2013 - 07:27 PM
You figured it out quite good yourself, you make it wait for an event, then you can use the if-then-else statements to figure out what to do with a certain touch. The correct event emitted is "monitor_touch" and not "mouse_click" though.


event, button, x, y = os.pullEvent("monitor_touch")
if x >= 5 and x <= 1 and y <= 1 and y >= 5 then
   print("hi")
else
   print("no")
end

You do not need to check if the event is a monitor_touch in your code, because you already made it in the os.pullEvent() that the only event it will record, is a monitor_touch. So if there is an event, it must be the monitor_touch.
1vannn #3
Posted 22 May 2013 - 05:46 PM
Alright, thanks. :)/>
Kingdaro #4
Posted 22 May 2013 - 09:18 PM
I'd like to add that the monitor_touch event returns different parameters from the mouse_click event, as you can only use right-click with the monitor (left-click would destroy it, middle-click would pick it). It actually returns the side that the monitor is on instead of the button, and returns the same x, y coords as the mouse_click event.
event, side, x, y = os.pullEvent("monitor_touch")