Advertisement
Theshadow989

Touch Screen

Feb 28th, 2018 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. mouseWidth = 0
  2. mouseHeight = 0
  3.  
  4. monitor = peripheral.wrap("bottom")
  5.  
  6. monitor.clear()
  7.  
  8. monitor.setCursorPos(1,1)
  9.  
  10. w,h=monitor.getSize()
  11.  
  12. print(w)
  13. print(h)
  14.  
  15. monitor.setBackgroundColour((colours.lime))
  16.  
  17. monitor.setCursorPos(2,2)
  18.  
  19. monitor.write(" ON  ")
  20.  
  21. monitor.setCursorPos(2,4)
  22.  
  23. monitor.write(" OFF ")
  24.  
  25. monitor.setBackgroundColour((colours.black))
  26.  
  27. function checkClickPosition()
  28.   if mouseWidth > 1 and mouseWidth < 8 and mouseHeight == 2 then
  29.     rs.setOutput("right",true)
  30.   elseif mouseWidth > 1 and mouseWidth < 8 and mouseHeight == 4 then
  31.     rs.setOutput("right",false)
  32.   end
  33. end
  34.  
  35. repeat
  36.  
  37.   event,p1,p2,p3 = os.pullEvent()
  38.  
  39.    if event=="monitor_touch" then
  40.  
  41.      mouseWidth = p2
  42.      mouseHeight = p3
  43.      checkClickPosition()
  44.      
  45.    end
  46.    
  47.    
  48. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement