Advertisement
theoriginalbit

ComputerCraft: Touchscreen Right-Click

Jan 15th, 2013
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. local timesTouched = 0
  2. local waitingForClicks = false
  3. local waitingPos = {}
  4. os.startTimer(0.4)
  5. while true do
  6.     local event = { os.pullEvent() }
  7.    
  8.     if event[1] == "monitor_touch" then
  9.         local xPos = event[3]
  10.         local yPos = event[4]
  11.        
  12.         timesTouched = timesTouched + 1
  13.        
  14.         if timesTouched < 2 then
  15.             waitingForClicks = true
  16.             waitingPos = {xPos, yPos}
  17.         elseif timesTouched == 2 then
  18.             os.queueEvent( "mouse_click", 2, xPos, yPos )
  19.             waitingForClicks = false
  20.         end
  21.     elseif event[1] == "mouse_click" then
  22.         print( event[2].." : "..event[3].." : "..event[4] )
  23.     elseif event[1] == "timer" then
  24.         timesTouched = 0
  25.         if waitingForClicks then
  26.             os.queueEvent( "mouse_click", 1, waitingPos[1], waitingPos[2] )
  27.         end
  28.         waitingForClicks = false
  29.         os.startTimer(0.4)
  30.     end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement