I made this post because I never found any information about creating touch sensitive terminals and I really wanted to make one, as my Lua knowledge was stunted, I started to look for API's. I thought they would be easier, but I won't lie, I struggled a lot! I know a few API's are great but I am going show you easiest way I learnt to make a touch screen on the terminal of an advanced computer.
Requirements:
+ Advanced Computer
Knowledge:
+ os.pullEvent (will help but not needed, the code will be displayed and tested)
+ variables in lua
+ this site: http://computercraft...ki/Os.pullEvent (this site has all the possible events that can be fired from os.pullEvent and all the arguments that come with it.
Basics:
Let's start with the:
os.pullEvent()
Here is an example of a touch point script:
local event, button, xPos, yPos = os.pullEvent("mouse_click")
+ The left click button will be the number 1
+ The right click button will be the number 2
+ The middle scroll wheel button click will be the number 3 (Note: Not rolling the wheel; but clicking it in! (Not all mouses have this))
So the "button" variable will be 1, 2, 3 depending on which button you press.
The "xPos" and "yPos" variables will be where the screen was pressed in screen characters. So this is the same measurements of the setCursorPos function.
So now when this code is run, it will give you all those vars (variables (cause I am lazy at times)) once you press on the screen. When dealing with these kind of controls you need to actually create a button to look at so we are gonna make a button that is 3x3 in size starting at X: 3 to X: 6 and Y: 3 to Y: 6. This is now a blue box (IMAGINE). Now you want to make it so you can press that button and only that button correct? (or maybe a set of buttons (will come to this later)). You will need to set up a simple if statement using the bigger than ">" and the lesser than "<" characters.
The IF statement:
To create a statement we are gonna use the following code that will allow us to press the button we talked about above:
local event, button, xPos, yPos = os.pullEvent("mouse_click")
if (xPos > 2 and xPos < 7) and (yPos > 2 and yPos < 7) then
  print("> You pressed the button!")
else
  print("> You missed the button!")
end
Using this allows you to create one box. Now we shall do some fixes!
Fix 1:
Using a loop will make it so that you have to press the button or it will repeat the mouse_click event until you do, here is the updated code:
while true do
  local event, button, xPos, yPos = os.pullEvent("mouse_click")
  if (xPos > 2 and xPos < 7) and (yPos > 2 and yPos < 7) then
	print("> You pressed the button!")
  else
	print("> You missed the button!")
  end
end
Fix 2:
Now to make it so we can run more than one event, we use an extra if statement before we even check whether the person pressed the button or not. This means you can wait for anything else as well as the mouse_click.
while true do
  local event, arg1, arg2, arg3 = os.pullEvent()
  if event == "mouse_click" then
	if (arg2 > 2 and arg2 < 7) and (arg3 > 2 and arg3 < 7) then
	  print("> You pressed the button!")
	else
	  print("> You missed the button!")
	end
  elseif event == "char" then
	charPressed = arg1
	print("You pressed a button on the keyboard!")
	print("You pressed: "..charPressed)
  end
end
Hope this helps any of you, need help? Message me:')
UPDATE:
As my knowledge has been expanded here is another version that allows you to (when choosing if you pressed the button) use <= or >= instead.
Here is the fix for the same example as above:
while true do
  local event, arg1, arg2, arg3 = os.pullEvent()
  if event == "mouse_click" then
	if (arg2 >= 3 and arg2 <= 6) and (arg3 >= 3 and arg3 <= 6) then
	  print("> You pressed the button!")
	else
	  print("> You missed the button!")
	end
  elseif event == "char" then
	charPressed = arg1
	print("You pressed a button on the keyboard!")
	print("You pressed: "..charPressed)
  end
end
 
         
                 
                 
                 
                