minecraftwarlock

Computercraft On-screen Keyboard

Apr 4th, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.58 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. if not term.isColor() then
  4.     error("Keyboard requires an advanced monitor")
  5. end
  6.  
  7. term.setBackgroundColor(colors.black)
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10.  
  11. local chars = {}
  12. local Key = {}
  13. chars[true] = {}
  14. chars[false] = {}
  15.  
  16. local lShiftPressed = false
  17. local rShiftPressed = false
  18.  
  19. local capsLkPressed = false
  20. local scrlLkPressed = false
  21. local numLkPressed = true
  22.  
  23. local lSuperPressed = false
  24. local rSuperPressed = false
  25.  
  26. local lAltPressed = false
  27. local rALtPressed = false
  28.  
  29. local lCtrlPressed = false
  30. local rCtrlPressed = false
  31.  
  32.  
  33. local terminateProgress = 0
  34. local rebootProgress = 0
  35. local shutdownProgress = 0
  36.  
  37.  
  38. --uppercase
  39. chars[true][2] = "!"
  40. chars[true][3] = "@"
  41. chars[true][4] = "#"
  42. chars[true][5] = "$"
  43. chars[true][6] = "%"
  44. chars[true][7] = "^"
  45. chars[true][8] = "&"
  46. chars[true][9] = "*"
  47. chars[true][10] = "("
  48. chars[true][11] = ")"
  49. chars[true][12] = "_"
  50. chars[true][13] = "+"
  51. chars[true][16] = "Q"
  52. chars[true][17] = "W"
  53. chars[true][18] = "E"
  54. chars[true][19] = "R"
  55. chars[true][20] = "T"
  56. chars[true][21] = "Y"
  57. chars[true][22] = "U"
  58. chars[true][23] = "I"
  59. chars[true][24] = "O"
  60. chars[true][25] = "P"
  61. chars[true][26] = "{"
  62. chars[true][27] = "}"
  63. chars[true][30] = "A"
  64. chars[true][31] = "S"
  65. chars[true][32] = "D"
  66. chars[true][33] = "F"
  67. chars[true][34] = "G"
  68. chars[true][35] = "H"
  69. chars[true][36] = "J"
  70. chars[true][37] = "K"
  71. chars[true][38] = "L"
  72. chars[true][39] = ":"
  73. chars[true][40] = "\""
  74. chars[true][41] = "~"
  75. chars[true][43] = "|"
  76. chars[true][44] = "Z"
  77. chars[true][45] = "X"
  78. chars[true][46] = "C"
  79. chars[true][47] = "V"
  80. chars[true][48] = "B"
  81. chars[true][49] = "N"
  82. chars[true][50] = "M"
  83. chars[true][51] = "<"
  84. chars[true][52] = ">"
  85. chars[true][53] = "?"
  86.  
  87.  
  88. --lowercase
  89. chars[false][2] = "1"
  90. chars[false][3] = "2"
  91. chars[false][4] = "3"
  92. chars[false][5] = "4"
  93. chars[false][6] = "5"
  94. chars[false][7] = "6"
  95. chars[false][8] = "7"
  96. chars[false][9] = "8"
  97. chars[false][10] = "9"
  98. chars[false][11] = "0"
  99. chars[false][12] = "-"
  100. chars[false][13] = "="
  101. chars[false][16] = "q"
  102. chars[false][17] = "w"
  103. chars[false][18] = "e"
  104. chars[false][19] = "r"
  105. chars[false][20] = "t"
  106. chars[false][21] = "y"
  107. chars[false][22] = "u"
  108. chars[false][23] = "i"
  109. chars[false][24] = "o"
  110. chars[false][25] = "p"
  111. chars[false][26] = "["
  112. chars[false][27] = "]"
  113. chars[false][30] = "a"
  114. chars[false][31] = "s"
  115. chars[false][32] = "d"
  116. chars[false][33] = "f"
  117. chars[false][34] = "g"
  118. chars[false][35] = "h"
  119. chars[false][36] = "j"
  120. chars[false][37] = "k"
  121. chars[false][38] = "l"
  122. chars[false][39] = ";"
  123. chars[false][40] = "'"
  124. chars[false][41] = "`"
  125. chars[false][43] = "\\"
  126. chars[false][44] = "z"
  127. chars[false][45] = "x"
  128. chars[false][46] = "c"
  129. chars[false][47] = "v"
  130. chars[false][48] = "b"
  131. chars[false][49] = "n"
  132. chars[false][50] = "m"
  133. chars[false][51] = ","
  134. chars[false][52] = "."
  135. chars[false][53] = "/"
  136.  
  137. Key.meta = {}
  138. Key.meta.__index = {}
  139.  
  140. local function xor(a, b)
  141.     return (not a and b) or (not b and a)
  142. end
  143.    
  144. function Key.meta.__index:draw()
  145.     term.setBackgroundColor(colors.red)
  146.     term.setCursorPos(self.x, self.y)
  147.     term.write(self:text())
  148.     term.setBackgroundColor(colors.black)
  149. end
  150.  
  151. function Key.meta.__index:click(x, y)
  152.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  153.         os.queueEvent("key", self.id)
  154.         if self:char() ~= nil then
  155.             os.queueEvent("char", self:char())
  156.         end
  157.     end
  158. end
  159.  
  160. function Key.meta.__index:text()
  161.     local t = self.textRaw
  162.     if type(t) == "function" then
  163.         t = t()
  164.     end
  165.     return t
  166. end
  167.  
  168. function Key.meta.__index:char()
  169.     return nil
  170. end
  171.  
  172. function Key.new(x, y, id, text)
  173.     local t = {["x"] = x, ["y"] = y, ["id"] = id, ["textRaw"] = text}
  174.     setmetatable(t, Key.meta)
  175.     return t
  176. end
  177.  
  178. function Key.capital(x, y, id)
  179.     local t = Key.new(x, y, id,
  180.         function()
  181.             return(chars[xor(lShiftPressed or rShiftPressed, capsLkPressed)][id])
  182.         end
  183.     )
  184.    
  185.     function t:click(x, y)
  186.         if self.y == y and self.x <= x and self.x + self:text():len() > x then
  187.             os.queueEvent("key", self.id)
  188.             if self:char() ~= nil then
  189.                 os.queueEvent("char", self:char())
  190.             end
  191.             lShiftPressed, rShiftPressed = false, false
  192.         end
  193.     end
  194.    
  195.     function t:char()
  196.         return self:text()
  197.     end
  198.     return t
  199. end
  200.  
  201. function Key.numpad(x, y, id, text)
  202.     local t = Key.new(x, y, id, text)
  203.    
  204.     function t:click(x, y)
  205.         if numLkPressed and self.y == y and self.x <= x and self.x + self:text():len() > x then
  206.             os.queueEvent("key", self.id)
  207.             if self:char() ~= nil then
  208.                 os.queueEvent("char", self:char())
  209.             end
  210.         end
  211.     end
  212.    
  213.     function t:char()
  214.         if self:text() == "Enter" then return nil end return self:text()
  215.     end
  216.    
  217.     return t
  218. end
  219.  
  220.  
  221. local Esc = Key.new(1, 1, 1, "Esc")
  222. local Key1 = Key.capital(3, 3, 2)
  223. local Key2 = Key.capital(5, 3, 3)
  224. local Key3 = Key.capital(7, 3, 4)
  225. local Key4 = Key.capital(9, 3, 5)
  226. local Key5 = Key.capital(11, 3, 6)
  227. local Key6 = Key.capital(13, 3, 7)
  228. local Key7 = Key.capital(15, 3, 8)
  229. local Key8 = Key.capital(17, 3, 9)
  230. local Key9 = Key.capital(19, 3, 10)
  231. local Key0 = Key.capital(21, 3, 11)
  232. local Minus = Key.capital(23, 3, 12)
  233. local Equals = Key.capital(25, 3, 13)
  234. local Backspace = Key.new(27, 3, 14, "Backspace")
  235. local Tab = Key.new(1, 5, 15, "Tab")
  236. local Q = Key.capital(5, 5, 16)
  237. local W = Key.capital(7, 5, 17)
  238. local E = Key.capital(9, 5, 18)
  239.  
  240. local R = Key.capital(11, 5, 19)
  241.  
  242. function R:click(x, y)
  243.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  244.         os.queueEvent("key", self.id)
  245.         if self:char() ~= nil then
  246.             os.queueEvent("char", self:char())
  247.         end
  248.         lShiftPressed, rShiftPressed = false, false
  249.         rebootProgress = rebootProgress + 1
  250.     end
  251. end
  252.  
  253. local T = Key.capital(13, 5, 20)
  254.  
  255. function T:click(x, y)
  256.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  257.         os.queueEvent("key", self.id)
  258.         if self:char() ~= nil then
  259.             os.queueEvent("char", self:char())
  260.         end
  261.         lShiftPressed, rShiftPressed = false, false
  262.         terminateProgress =  terminateProgress + 1
  263.     end
  264. end
  265.  
  266. local Y = Key.capital(15, 5, 21)
  267. local U = Key.capital(17, 5, 22)
  268. local I = Key.capital(19, 5, 23)
  269. local O = Key.capital(21, 5, 24)
  270. local P = Key.capital(23, 5, 25)
  271. local OpenSquareBracket = Key.capital(25, 5, 26)
  272. local ClosedSquareBracket = Key.capital(27, 5, 27)
  273. local Enter = Key.new(31, 7, 28, "Enter")
  274.  
  275. local LCtrl = Key.new(1, 11, 29, "Ctrl")
  276.  
  277. function LCtrl:click(x, y)
  278.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  279.         if not lCtrlPressed then os.queueEvent("key", self.id) end
  280.         if self:char() ~= nil then
  281.             os.queueEvent("char", self:char())
  282.         end
  283.         lCtrlPressed = not lCtrlPressed
  284.     end
  285. end
  286.  
  287. function LCtrl:draw()
  288.     if(not lCtrlPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  289.     term.setCursorPos(self.x, self.y)
  290.     term.write(self:text())
  291.     term.setBackgroundColor(colors.black)
  292. end
  293.  
  294. local A = Key.capital(9, 7, 30)
  295.  
  296. local S = Key.capital(11, 7, 31)
  297.  
  298. function S:click(x, y)
  299.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  300.         os.queueEvent("key", self.id)
  301.         if self:char() ~= nil then
  302.             os.queueEvent("char", self:char())
  303.         end
  304.         lShiftPressed, rShiftPressed = false, false
  305.         shutdownProgress = shutdownProgress + 1
  306.     end
  307. end
  308.  
  309. local D = Key.capital(13, 7, 32)
  310. local F = Key.capital(15, 7, 33)
  311. local G = Key.capital(17, 7, 34)
  312. local H = Key.capital(19, 7, 35)
  313. local J = Key.capital(21, 7, 36)
  314. local K = Key.capital(23, 7, 37)
  315. local L = Key.capital(25, 7, 38)
  316. local SemiColon = Key.capital(27, 7, 39)
  317. local Quote = Key.capital(29, 7, 40)
  318. local Grave = Key.capital(1, 3, 41)
  319.  
  320. local LShift = Key.new(1, 9, 42, "Shift")
  321.  
  322. function LShift:click(x, y)
  323.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  324.         if not lShiftPressed then os.queueEvent("key", self.id) end
  325.         if self:char() ~= nil then
  326.             os.queueEvent("char", self:char())
  327.         end
  328.         lShiftPressed = not lShiftPressed
  329.     end
  330. end
  331.  
  332. function LShift:draw()
  333.     if(not lShiftPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  334.     term.setCursorPos(self.x, self.y)
  335.     term.write(self:text())
  336.     term.setBackgroundColor(colors.black)
  337. end
  338.  
  339. local Backslash = Key.capital(29, 5, 43)
  340. local Z = Key.capital(7, 9, 44)
  341. local X = Key.capital(9, 9, 45)
  342. local C = Key.capital(11, 9, 46)
  343. local V = Key.capital(13, 9, 47)
  344. local B = Key.capital(15, 9, 48)
  345. local N = Key.capital(17, 9, 49)
  346. local M = Key.capital(19, 9, 50)
  347. local Comma = Key.capital(21, 9, 51)
  348. local Period = Key.capital(23, 9, 52)
  349. local Slash = Key.capital(25, 9, 53)
  350. local RShift = Key.new(27, 9, 54, "Shift")
  351. local NumAsterisk = Key.numpad(63, 3, 55, "*")
  352.  
  353. local LCtrl = Key.new(1, 11, 29, "Ctrl")
  354.  
  355. function LCtrl:click(x, y)
  356.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  357.         if not lCtrlPressed then os.queueEvent("key", self.id) end
  358.         if self:char() ~= nil then
  359.             os.queueEvent("char", self:char())
  360.         end
  361.         lCtrlPressed = not lCtrlPressed
  362.     end
  363. end
  364.  
  365. function LCtrl:draw()
  366.     if(not lCtrlPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  367.     term.setCursorPos(self.x, self.y)
  368.     term.write(self:text())
  369.     term.setBackgroundColor(colors.black)
  370. end
  371.  
  372. local A = Key.capital(9, 7, 30)
  373. local S = Key.capital(11, 7, 31)
  374. local D = Key.capital(13, 7, 32)
  375. local F = Key.capital(15, 7, 33)
  376. local G = Key.capital(17, 7, 34)
  377. local H = Key.capital(19, 7, 35)
  378. local J = Key.capital(21, 7, 36)
  379. local K = Key.capital(23, 7, 37)
  380. local L = Key.capital(25, 7, 38)
  381. local SemiColon = Key.capital(27, 7, 39)
  382. local Quote = Key.capital(29, 7, 40)
  383. local Grave = Key.capital(1, 3, 41)
  384.  
  385. local LAlt = Key.new(8, 11, 56, "Alt")
  386.  
  387. function LAlt:click(x, y)
  388.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  389.         if not lALtPressed then os.queueEvent("key", self.id) end
  390.         if self:char() ~= nil then
  391.             os.queueEvent("char", self:char())
  392.         end
  393.         lAltPressed = not lAltPressed
  394.     end
  395. end
  396.  
  397. function LAlt:draw()
  398.     if(not lAltPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  399.     term.setCursorPos(self.x, self.y)
  400.     term.write(self:text())
  401.     term.setBackgroundColor(colors.black)
  402. end
  403.  
  404. local Space = Key.new(12, 11, 57, "         ")
  405.  
  406. function Space:char()
  407.     return " "
  408. end
  409.  
  410. local CapsLk = Key.new(1, 7, 58, "Caps Lk")
  411.  
  412. function CapsLk:click(x, y)
  413.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  414.         os.queueEvent("key", self.id)
  415.         if self:char() ~= nil then
  416.             os.queueEvent("char", self:char())
  417.         end
  418.         capsLkPressed = not capsLkPressed
  419.     end
  420. end
  421.  
  422. function CapsLk:draw()
  423.     if(not capsLkPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  424.     term.setCursorPos(self.x, self.y)
  425.     term.write(self:text())
  426.     term.setBackgroundColor(colors.black)
  427. end
  428.  
  429. local F1 = Key.new(5, 1, 59, "F1")
  430. local F2 = Key.new(8, 1, 60, "F2")
  431. local F3 = Key.new(11, 1, 61, "F3")
  432. local F4 = Key.new(14, 1, 62, "F4")
  433. local F5 = Key.new(17, 1, 63, "F5")
  434. local F6 = Key.new(20, 1, 64, "F6")
  435. local F7 = Key.new(23, 1, 65, "F7")
  436. local F8 = Key.new(26, 1, 66, "F8")
  437. local F9 = Key.new(29, 1, 67, "F9")
  438. local F10 = Key.new(32, 1, 68, "F10")
  439.  
  440. local NumLk = Key.new(54, 3, 69, "Num Lk")
  441.  
  442. function NumLk:click(x, y)
  443.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  444.         os.queueEvent("key", self.id)
  445.         if self:char() ~= nil then
  446.             os.queueEvent("char", self:char())
  447.         end
  448.         numLkPressed = not numLkPressed
  449.     end
  450. end
  451.  
  452. function NumLk:draw()
  453.     if(not numLkPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  454.     term.setCursorPos(self.x, self.y)
  455.     term.write(self:text())
  456.     term.setBackgroundColor(colors.black)
  457. end
  458.  
  459. local ScrollLk = Key.new(53, 1, 70, "Scrl Lk")
  460.  
  461. function ScrollLk:click(x, y)
  462.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  463.         os.queueEvent("key", self.id)
  464.         if self:char() ~= nil then
  465.             os.queueEvent("char", self:char())
  466.         end
  467.         scrlLkPressed = not scrlLkPressed
  468.     end
  469. end
  470.  
  471. function ScrollLk:draw()
  472.     if(not scrlLkPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  473.     term.setCursorPos(self.x, self.y)
  474.     term.write(self:text())
  475.     term.setBackgroundColor(colors.black)
  476. end
  477.  
  478. local Num7 = Key.numpad(59, 5, 71, "7")
  479. local Num8 = Key.numpad(61, 5, 72, "8")
  480. local Num9 = Key.numpad(63, 5, 73, "9")
  481. local NumMinus = Key.numpad(65, 3, 74, "-")
  482. local Num4 = Key.numpad(59, 7, 75, "4")
  483. local Num5 = Key.numpad(61, 7, 76, "5")
  484. local Num6 = Key.numpad(63, 7, 77, "6")
  485. local NumPlus = Key.numpad(65, 5, 78, "+")
  486. local Num1 = Key.numpad(59, 9, 79, "1")
  487. local Num2 = Key.numpad(61, 9, 80, "2")
  488. local Num3 = Key.numpad(63, 9, 81, "3")
  489. local Num0 = Key.numpad(59, 11, 82, "0")
  490. local NumPeriod = Key.numpad(61, 11, 83, ".")
  491. local NumEnter = Key.numpad(63, 11, 28, "Enter")
  492. local F11 = Key.new(36, 1, 87, "F11")
  493. local F12 = Key.new(40, 1, 88, "F12")
  494.  
  495. local RCtrl = Key.new(33, 11, 157, "Ctrl")
  496.  
  497. function RCtrl:click(x, y)
  498.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  499.         if not rCtrlPressed then os.queueEvent("key", self.id) end
  500.         if self:char() ~= nil then
  501.             os.queueEvent("char", self:char())
  502.         end
  503.         rCtrlPressed = not rCtrlPressed
  504.     end
  505. end
  506.  
  507. function RCtrl:draw()
  508.     if(not rCtrlPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  509.     term.setCursorPos(self.x, self.y)
  510.     term.write(self:text())
  511.     term.setBackgroundColor(colors.black)
  512. end
  513.  
  514. local NumSlash = Key.numpad(61, 3, 181, "/")
  515. local PrntScrn = Key.new(44, 1, 183, "PrntScrn")
  516.  
  517. local RAlt = Key.new(22, 11, 184, "Alt")
  518.  
  519. function RAlt:click(x, y)
  520.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  521.         if not rALtPressed then os.queueEvent("key", self.id) end
  522.         if self:char() ~= nil then
  523.             os.queueEvent("char", self:char())
  524.         end
  525.         rAltPressed = not rAltPressed
  526.     end
  527. end
  528.  
  529. function RAlt:draw()
  530.     if(not rAltPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  531.     term.setCursorPos(self.x, self.y)
  532.     term.write(self:text())
  533.     term.setBackgroundColor(colors.black)
  534. end
  535.  
  536. local Pause = Key.new(61, 1, 197, "Pause")
  537. local Home = Key.new(41, 3, 199, "Home")
  538. local Up = Key.new(47, 9, 200, "^")
  539. local PgUp = Key.new(46, 3, 201, "Pg Up")
  540. local Left = Key.new(45, 11, 203, "<")
  541. local Right = Key.new(49, 11, 205, ">")
  542. local End = Key.new(41, 5, 207, "End")
  543. local Down = Key.new(47, 11, 208, "v")
  544. local PgDown = Key.new(46, 5, 209, "Pg Dn")
  545. local Ins = Key.new(37, 3, 210, "Ins")
  546. local Del = Key.new(37, 5, 211, "Del")
  547.  
  548. local LSuper = Key.new(6, 11, 219, "#")
  549.  
  550. function LSuper:click(x, y)
  551.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  552.         if not lSuperPressed then os.queueEvent("key", self.id) end
  553.         if self:char() ~= nil then
  554.             os.queueEvent("char", self:char())
  555.         end
  556.         lSuperPressed = not lSuperPressed
  557.     end
  558. end
  559.  
  560. function LSuper:draw()
  561.     if(not lSuperPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  562.     term.setCursorPos(self.x, self.y)
  563.     term.write(self:text())
  564.     term.setBackgroundColor(colors.black)
  565. end
  566.  
  567. local RSuper = Key.new(26, 11, 220, "#")
  568.  
  569. function RSuper:click(x, y)
  570.     if self.y == y and self.x <= x and self.x + self:text():len() > x then
  571.         if not rSuperPressed then os.queueEvent("key", self.id) end
  572.         if self:char() ~= nil then
  573.             os.queueEvent("char", self:char())
  574.         end
  575.         rSuperPressed = not rSuperPressed
  576.     end
  577. end
  578.  
  579. function RSuper:draw()
  580.     if(not rSuperPressed)then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lime) end
  581.     term.setCursorPos(self.x, self.y)
  582.     term.write(self:text())
  583.     term.setBackgroundColor(colors.black)
  584. end
  585.  
  586. local Menu = Key.new(28, 11, 221, "Menu")
  587.  
  588. local Keys = {
  589.       Esc, Key1, Key2, Key3, Key4
  590.     , Key5, Key6, Key7, Key8, Key9
  591.     , Key0, Minus, Equals, Backspace, Tab
  592.     , Q, W, E, R, T
  593.     , Y, U, I, O, P
  594.     , OpenSquareBracket, ClosedSquareBracket, Enter, LCtrl, A
  595.     , S, D, F, G, H
  596.     , J, K, L, SemiColon, Quote
  597.     , Grave, LShift, Backslash, Z, X
  598.     , C, V, B, N, M
  599.     , Comma, Period, Slash, RShift, NumAsterisk
  600.     , LAlt, Space, CapsLk, F1, F2
  601.     , F3, F4, F5, F6, F7
  602.     , F8, F9, F10, NumLk, ScrollLk
  603.     , Num7, Num8, Num9, NumMinus, Num4
  604.     , Num5, Num6, NumPlus, Num1, Num2
  605.     , Num3, Num0, NumPeriod, NumEnter, F11
  606.     , F12, RCtrl, NumSlash, PrntScrn, RAlt
  607.     , Pause, Home, Up, PgUp, Left
  608.     , Right, End, Down, PgDown, Ins
  609.     , Del, LSuper, RSuper, Menu
  610. }
  611.  
  612.  
  613. for k, v in pairs(Keys) do
  614.     if type(v) == "table" then
  615.         v:draw()
  616.     end
  617. end
  618.  
  619. local function hanldleMonitor()
  620.     while true do
  621.         event, side, x, y = os.pullEvent("monitor_touch")
  622.         if side == tArgs[1] then
  623.             --handle events
  624.             for k, v in pairs(Keys) do
  625.                 v:click(x, y)
  626.             end
  627.             --redraw keys
  628.             for k, v in pairs(Keys) do
  629.                 v:draw()
  630.             end
  631.         end
  632.     end
  633. end
  634.  
  635. local function queueEvents()
  636.     while true do
  637.         if lShiftPressed then os.queueEvent("key", LShift.id) end
  638.         if rShiftPressed then os.queueEvent("key", RShift.id) end
  639.  
  640.         if lSuperPressed then os.queueEvent("key", LSuper.id) end
  641.         if rSuperPressed then os.queueEvent("key", RSuper.id) end
  642.  
  643.         if lAltPressed then os.queueEvent("key", LAlt.id) end
  644.         if rALtPressed then os.queueEvent("key", RAlt.id) end
  645.  
  646.         if lCtrlPressed then os.queueEvent("key", LCtrl.id) end
  647.         if rCtrlPressed then os.queueEvent("key", RCtrl.id) end
  648.         sleep(0.3)
  649.     end
  650. end
  651.  
  652. local function handleReboot()
  653.     while true do
  654.         if terminateProgress >= 5 then os.queueEvent("terminate") end
  655.         if rebootProgress >= 5 then os.reboot() end
  656.         if shutdownProgress >= 5 then os.shutdown() end
  657.         terminateProgress = 0
  658.         rebootProgress = 0
  659.         shutdownProgress = 0
  660.         sleep(1)
  661.     end
  662. end
  663.  
  664. parallel.waitForAny(hanldleMonitor, queueEvents, handleReboot)
Advertisement
Add Comment
Please, Sign In to add comment