Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("right") -- Change "right" to the side where the monitor is connected.
- local button = {x1 = 2, y1 = 2, x2 = 10, y2 = 4, label = "Click me"}
- function drawButton()
- monitor.setBackgroundColor(colors.white)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(button.x1, button.y1)
- for i = button.y1, button.y2 do
- monitor.setCursorPos(button.x1, i)
- monitor.write(string.rep(" ", button.x2 - button.x1 + 1))
- end
- monitor.setCursorPos(button.x1 + 2, button.y1 + 1)
- monitor.write(button.label)
- end
- function isInsideButton(x, y)
- return x >= button.x1 and x <= button.x2 and y >= button.y1 and y <= button.y2
- end
- function waitForClick()
- while true do
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if isInsideButton(xPos, yPos) then
- print("Button clicked!")
- -- Add any action you want to perform when the button is clicked.
- end
- end
- end
- monitor.clear()
- drawButton()
- waitForClick()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement