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

Q:How do you make clicakble buttons on touchscreens?

Started by Zambonie, 27 December 2012 - 01:24 PM
Zambonie #1
Posted 27 December 2012 - 02:24 PM
Yes,touchscreens are out,and im making an touchscreen version of my calc.I did hear that proboly you need to add a special code to do that for touchscreens,just I dont know it.And Also,if anyone can answer this to: How do I get the computer to get the size of my monitor and center the text in the middle?Because,there are these strange whit boxes on my monitor,showing the size of an single letter,and my monitor is huge!And so I dont want to count them all…Well,you dont really need to worry about those white boxes part.Just telling you.And there kinda getting annoying…
Lyqyd #2
Posted 27 December 2012 - 02:30 PM
Monitor peripheral functions, and the monitor_touch event. monitor_touch events also return side, x, y.
remiX #3
Posted 27 December 2012 - 09:11 PM
Here's a basic code:


mon = peripheral.wrap("left")
mX, mY = mon.getSize()

while true do
    event, click, x, y = os.pullEvent()
    if event == "monitor_touch" then
        if y ==  1 then -- if 'y' is 1 then this is true
            mon.setCursorPos(1,3)
            mon.write("You clicked the first line of the monitor!")
        elseif x >= 1 and x <= mX/2 and y == 2 then -- if x is between 1 and half of the mX and y is 2 then this is true
            mon.setCursorPos(1,4)
            mon.write("You clicked the first half of the second line!")
        end
    end
end