KevY007

Touch Keyboard (WIP)

Jul 23rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. os.loadAPI("/apis/touchpoint")
  2. --------------------------------------
  3. monside = "none"
  4. --------------------------------------
  5. function updateMonitorSide()
  6.   if peripheral.getType("top") == "monitor" then
  7.     monside = "top"
  8.   elseif peripheral.getType("bottom") == "monitor" then
  9.     monside = "bottom"
  10.   elseif peripheral.getType("right") == "monitor" then
  11.     monside = "right"
  12.   elseif peripheral.getType("left") == "monitor" then
  13.     monside = "left"
  14.   elseif peripheral.getType("front") == "monitor" then
  15.     monside = "front"
  16.   elseif peripheral.getType("back") == "monitor" then
  17.     monside = "back"
  18.   end
  19.   local periLists = peripheral.getNames()
  20.   for i = 1, #periLists do
  21.     if peripheral.getType(periLists[i]) == "monitor" then
  22.       monside = periLists[i]
  23.     end
  24.   end
  25. end
  26. function getMonMid(text)
  27.   if peripheral.getType(monside) == "monitor" then
  28.     local monn = peripheral.wrap(monside)
  29.     local x, y = monn.getSize()
  30.     local cY = y/2
  31.     local cX = math.floor(x-string.len(text))/2
  32.     return cX, cY
  33.   else
  34.     return 0, 0
  35.   end
  36. end
  37. --------------------------------------
  38. updateMonitorSide()
  39. if monside == "none" then
  40.   error("Couldn't find any monitors!")
  41. else
  42.   local oldcol = term.getTextColor()
  43.   term.setTextColor(colors.green)
  44.   write("Found Monitor on " ..monside .. " side.\n")
  45.   term.setTextColor(oldcol)
  46. end
  47. monitorget = peripheral.wrap(monside)
  48. local monw, monh = monitorget.getSize()
  49. monitorget.clear()
  50. tp = touchpoint.new(monside)
  51. monitorget.setTextScale(1.5)
  52. tp:add("a", nil, 2, 11, 2, 11, colors.red, colors.white)
  53. monitorget.setTextScale(1.5)
  54. tp:draw()
  55.  
  56. while true do
  57.   local evenk, args1 = os.pullEvent()
  58.   if evenk == "key" then
  59.     monitorget.clear()
  60.     monitorget.setCursorPos(1,1)
  61.     monitorget.write(keys.getName(args1))
  62.     print(keys.getName(args1))
  63.     tp:draw()
  64.   end
  65.   local event, btn = tp:handleEvents(os.pullEvent())
  66.   if event == "button_click" then
  67.     if btn == "a" then
  68.       print("Pressed a")
  69.       os.queueEvent("key", 30)
  70.     end
  71.     tp:toggleButton(btn)
  72.     tp:draw()
  73.        sleep(0.1)
  74.        tp:toggleButton(btn)
  75.     tp:draw()
  76.   end
  77. end
Add Comment
Please, Sign In to add comment