ComputerMan123

ccKeyboard (by TheOriginalBit)

Feb 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.29 KB | None | 0 0
  1. --[[
  2. Author: TheOriginalBIT
  3. Version: 1.0
  4. Created: 25 Mar 2013
  5. Last Update: 25 Mar 2013
  6.  
  7. License:
  8.  
  9. COPYRIGHT NOTICE
  10. Copyright © 2013 Joshua Asbury a.k.a TheOriginalBIT [theoriginalbit@gmail.com]
  11.  
  12. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  13. associated documentation files (the "Software"), to deal in the Software without restriction,
  14. including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. copies of the Software, and to permit persons to whom the Software is furnished to do so,
  16. subject to the following conditions:
  17.  
  18. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  19. -Visible credit is given to the original author.
  20. -The software is distributed in a non-profit way.
  21.  
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  23. WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  24. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. ]]--
  27.  
  28. local views = {}
  29. local cycleInfo = {}
  30. local cycleInfoSub = {}
  31. local activeView = nil
  32. local monitorSide = nil
  33. local monitorObj = nil
  34. local offset_x, offset_y = 0, 0
  35.  
  36. local shiftPressed = false
  37. local capsLockPressed = false
  38. local shiftLastPressed = 0
  39. local doubleClickSpeed = 0
  40. local routineKeyboard = nil
  41.  
  42. _G.assert = function(condition, errMsg, level) if not condition then error(errMsg, (tonumber(level) or 1) + 1) end return condition end
  43.  
  44. local function cycleActiveScreen()
  45. if cycleInfo[activeView] then
  46. activeView = cycleInfo[activeView]._next
  47. elseif cycleInfoSub[activeView] then
  48. activeView = cycleInfoSub[activeView]._next
  49. else
  50. error('Attempting to cycle from invalid screen', 2)
  51. end
  52. end
  53.  
  54. --[[
  55.  
  56. ########################### API ###########################
  57.  
  58. ]]--
  59.  
  60. function setActiveScreen(key)
  61. assert(views[key], 'A screen with the key \''..key..'\' does not exist', 2)
  62. activeView = key
  63. end
  64.  
  65. function setNext(key, next)
  66. assert(cycleInfo[key], 'A screen with the key \''..key..'\' does not exist', 2)
  67. cycleInfo[key]._next = next
  68. end
  69.  
  70. function setPrev(key, prev)
  71. assert(views[key], 'A screen with the key \''..key..'\' does not exist', 2)
  72. cycleInfo[key]._prev = prev
  73. end
  74.  
  75. function setCycleKeyFunc(screen, func)
  76. assert(views[screen], 'A screen with the key \''..screen..'\' does not exist', 2)
  77. assert(type(func) == 'function', 'Invalid parameter: expected function, got '..type(func), 2)
  78. views[screen].__SP__.onClick = function( ... )
  79. func(...)
  80. shiftPressed = false
  81. end
  82. end
  83.  
  84. function setDoubleClickSpeed(s)
  85. assert(type(s) == 'number', 'Invalid parameter: expected number, got '..type(s), 2)
  86. assert(s > 0.1 or s == 0, 'Invalid parameter: double click speed cannot be set to faster than 0.1', 2)
  87. assert(s < 0.5, 'Invalid parameter: double click speed cannot be set to slower than 0.5', 2)
  88.  
  89. if s == 0 and emulog then
  90. emulog.log('WARNING: You are disabling double click; This means that the user will not be able to activate caps lock;')
  91. end
  92. doubleClickSpeed = s
  93. end
  94.  
  95. function registerKey(screen, key, text, xPos, yPos, width, height, func, backColor, textColor)
  96. assert(views[screen], 'A screen with the key \''..screen..'\' does not exist', 2)
  97. assert(not views[screen][key], 'A key with the key \''..key..'\' already exists', 2)
  98. assert(type(text) == 'string', 'Invalid parameter: expected text to be a string, got '..type(text), 2)
  99. assert(type(xPos) == 'number', 'Invalid parameter: expected xPos to be a number, got '..type(xPos), 2)
  100. assert(type(yPos) == 'number', 'Invalid parameter: expected yPos to be a number, got '..type(yPos), 2)
  101. assert(type(width) == 'number' or type(width) == 'nil', 'Invalid parameter: expected width to be a number or nil, got '..type(width), 2)
  102. assert(type(height) == 'number' or type(height) == 'nil', 'Invalid parameter: expected height to be a number or nil, got '..type(height), 2)
  103. assert(type(func) == 'function', 'Invalid parameter: expected func to be a function, got '..type(func), 2)
  104. assert(type(backColor) == 'number' and backColor >= 2^0 and backColor <= 2^15, 'Invalid parameter: expected backColor to be a number color, got '..type(backColor), 2)
  105. assert(type(textColor) == 'number' and textColor >= 2^0 and textColor <= 2^15, 'Invalid parameter: expected textColor to be a number color, got '..type(textColor), 2)
  106.  
  107. views[screen][key] = {}
  108. views[screen][key]._t = text
  109. views[screen][key]._x = xPos
  110. views[screen][key]._y = yPos
  111. views[screen][key]._w = width or #text
  112. views[screen][key]._h = height or 1
  113. views[screen][key]._bc = backColor
  114. views[screen][key]._tc = textColor
  115. views[screen][key].onClick = key == 'SF' and func or function( ... )
  116. func(...)
  117. shiftPressed = false -- turn off shift, we have done our capital letter
  118. end
  119. views[screen][key].wasClicked = function(self, mouse_x, mouse_y)
  120. return mouse_x >= self._x + offset_x and mouse_x <= self._x + offset_x + self._w - 1 and mouse_y >= self._y + offset_y and mouse_y <= self._y + offset_y + self._h - 1
  121. end
  122. views[screen][key].onDraw = function(self)
  123. if self._t == '^ ' then
  124. if capsLockPressed then
  125. term.setBackgroundColor(colors.blue)
  126. elseif shiftPressed then
  127. term.setBackgroundColor(colors.lightBlue)
  128. end
  129. else
  130. term.setBackgroundColor(self._bc)
  131. end
  132.  
  133. term.setTextColor(self._t == '^ ' and capsLockPressed and colors.white or self._tc)
  134. for y = 0, self._h - 1 do
  135. term.setCursorPos(offset_x + self._x, offset_y + self._y + y)
  136. write( string.rep(' ', self._w) )
  137. end
  138.  
  139. term.setCursorPos(offset_x + self._x + math.floor(self._w / 2 - #self._t / 2), offset_y + self._y + math.floor(self._h / 2))
  140. if (shiftPressed or capsLockPressed) and not (self._t == ' space ' or self._t == 'enter') then
  141. write(string.upper(self._t) or '?')
  142. elseif self._t == 'ERR' then
  143. if cycleInfo[activeView] then
  144. write(cycleInfo[activeView]._next or '???')
  145. elseif cycleInfoSub[activeView] then
  146. write(cycleInfoSub[activeView]._next or '???')
  147. else
  148. local _, cy = term.getCursorPos()
  149. term.setCursorPos(1, cy)
  150. error('Attempting to print a screen that has no next', 2)
  151. end
  152. else
  153. write(self._t or '?')
  154. end
  155. end
  156. end
  157.  
  158. function registerScreen(key, prev_screen, next_screen)
  159. emulog.log('REG:'..tostring(not views[key]))
  160. assert(not views[key], 'A screen with the key \''..key..'\' already exists', 2)
  161. assert(type(prev_screen) == 'string', 'Invalid parameter: expected prev_screen to be a string, got '..type(prev_screen), 2)
  162. assert(type(next_screen) == 'string', 'Invalid parameter: expected next_screen to be a string, got '..type(next_screen), 2)
  163. views[key] = {}
  164. cycleInfo[key] = { _prev = prev_screen, _next = next_screen}
  165. registerKey(key, '__SP__', 'ERR', 1, 4, 3, nil, function() cycleActiveScreen() end, colors.lightGray, colors.black)
  166. end
  167.  
  168. function registerSubScreen(key, prev_screen, next_screen)
  169. emulog.log('SUB-REG:'..tostring(not views[key]))
  170. assert(not views[key], 'A screen with the key \''..key..'\' already exists', 2)
  171. assert(type(prev_screen) == 'string', 'Invalid parameter: expected prev_screen to be a string, got '..type(prev_screen), 2)
  172. assert(type(next_screen) == 'string', 'Invalid parameter: expected next_screen to be a string, got '..type(next_screen), 2)
  173. views[key] = {}
  174. cycleInfoSub[key] = { _prev = prev_screen, _next = next_screen}
  175. registerKey(key, '__SP__', 'ERR', 1, 4, 3, nil, function() cycleActiveScreen() end, colors.lightGray, colors.black)
  176. end
  177.  
  178. --[[
  179.  
  180. ########################### END API ###########################
  181.  
  182. ]]--
  183.  
  184. function render()
  185. if onMonitor then
  186. term.redirect(monitorObj)
  187. end
  188.  
  189. term.setBackgroundColor(colors.lightGray)
  190.  
  191. for i = 1, 4 do
  192. term.setCursorPos(offset_x + 1, offset_y + i)
  193. write( string.rep(' ', 19) )
  194. end
  195.  
  196. for _,v in pairs(views[activeView]) do
  197. v:onDraw()
  198. end
  199.  
  200. if onMonitor then
  201. term.restore()
  202. end
  203. end
  204.  
  205. local function run()
  206. while true do
  207. local event = { coroutine.yield() }
  208. if event[1] == 'terminate' then
  209. return
  210. elseif (onMonitor and event[1] == 'monitor_touch' and event[2] == monitorSide) or (not onMonitor and event[1] == 'mouse_click') then
  211. for _, v in pairs(views[activeView]) do
  212. if v:wasClicked( event[3], event[4]) then
  213. v:onClick()
  214. break -- a button was clicked, we don't have stacked buttons
  215. end
  216. end
  217. end
  218. end
  219. end
  220.  
  221. function pullEvent(useRaw)
  222. local pullEvent = useRaw and os.pullEventRaw or os.pullEvent
  223. local event = { pullEvent() }
  224. coroutine.resume(routineKeyboard, unpack(event) )
  225. return unpack(event)
  226. end
  227.  
  228. function isAlive()
  229. return routineKeyboard and coroutine.status(routineKeyboard) ~= 'dead'
  230. end
  231.  
  232. function startCoroutine()
  233. if not routineKeyboard or not isAlive() then
  234. routineKeyboard = coroutine.create(run)
  235. end
  236. coroutine.resume(routineKeyboard)
  237. end
  238.  
  239. local function setupOffsets(x, y, w, h)
  240. if x then
  241. offset_x = x
  242. end
  243. if y then
  244. offset_y = y
  245. end
  246.  
  247. if offset_x == 'center' then
  248. offset_x = math.ceil(w / 2 - 19 / 2)
  249. end
  250.  
  251. if offset_y == 'center' then
  252. offset_y = math.ceil(h / 2 - 2 )
  253. end
  254. end
  255.  
  256. function setup( topLeftX, topLeftY, onMonitor, side )
  257. local w, h
  258.  
  259. onMonitor = onMonitor ~= false
  260.  
  261. if onMonitor then
  262. assert(type(side) == 'string', 'Invalid parameter: expected side to be a string, got '..type(side), 2)
  263. if peripheral.getType(side) ~= 'monitor' then printError('No monitor on the computers '..side..' side') error() end
  264. monitorSide = side
  265. monitorObj = peripheral.wrap(side)
  266. if not monitorObj.isColor() then printError('Monitor must be an advanced monitor') error() end
  267. monitorObj.setTextScale(1)
  268.  
  269. local mw, mh = monitorObj.getSize()
  270. local scale = mw / 19
  271. if scale > 5 then scale = 5 end
  272. if scale < 0.5 then scale = 0.5 end
  273. monitorObj.setTextScale(scale)
  274.  
  275. term.redirect(monitorObj)
  276. w, h = term.getSize()
  277. term.restore()
  278.  
  279. setupOffsets(topLeftX, topLeftY, w, h)
  280.  
  281. if w < 19 then
  282. printError('Monitor is not wide enough to display keyboard')
  283. error()
  284. end
  285. if h < 4 then
  286. printError('Monitor is not tall enough to display keyboard')
  287. error()
  288. end
  289. else
  290. w, h = term.getSize()
  291. end
  292.  
  293. setupOffsets(topLeftX, topLeftY, w, h)
  294.  
  295. if offset_y + 4 > h then
  296. error('Cannot display keyboard off screen. Pixels are '..math.abs(offset_y + 4 - h)..' row(s) off the bottom of the screen', 2)
  297. elseif offset_y < 1 then
  298. error('Cannot display keyboard off screen. Pixels are '..math.abs(offset_y)..' row(s) off the top of the screen', 2)
  299. end
  300. if offset_x + 19 > w then
  301. error('Cannot display keyboard off screen. Pixels are '..math.abs(offset_x + 19 - w)..' column(s) off the right of the screen', 2)
  302. elseif offset_x < 0 then
  303. error('Cannot display keyboard off screen. Pixels are '..math.abs(offset_x)..' column(s) off the left of the screen', 2)
  304. end
  305.  
  306.  
  307.  
  308. registerScreen('ABC', '123', '123')
  309. registerScreen('123', 'ABC', 'ABC')
  310. registerSubScreen('#+=', '123', '123')
  311.  
  312. setActiveScreen('ABC')
  313. setDoubleClickSpeed(0.2)
  314.  
  315. -- FIRST VIEW: ABC
  316. do
  317. -- First row, ASCII keyboard
  318. registerKey('ABC', 'q', 'q', 1, 1, nil, nil, function() os.queueEvent('key', keys.q) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'Q' or 'q') end, colors.lightGray, colors.black)
  319. registerKey('ABC', 'w', 'w', 3, 1, nil, nil, function() os.queueEvent('key', keys.w) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'W' or 'w') end, colors.lightGray, colors.black)
  320. registerKey('ABC', 'e', 'e', 5, 1, nil, nil, function() os.queueEvent('key', keys.e) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'E' or 'e') end, colors.lightGray, colors.black)
  321. registerKey('ABC', 'r', 'r', 7, 1, nil, nil, function() os.queueEvent('key', keys.r) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'R' or 'r') end, colors.lightGray, colors.black)
  322. registerKey('ABC', 't', 't', 9, 1, nil, nil, function() os.queueEvent('key', keys.t) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'T' or 't') end, colors.lightGray, colors.black)
  323. registerKey('ABC', 'y', 'y', 11, 1, nil, nil, function() os.queueEvent('key', keys.y) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'Y' or 'y') end, colors.lightGray, colors.black)
  324. registerKey('ABC', 'u', 'u', 13, 1, nil, nil, function() os.queueEvent('key', keys.u) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'U' or 'u') end, colors.lightGray, colors.black)
  325. registerKey('ABC', 'i', 'i', 15, 1, nil, nil, function() os.queueEvent('key', keys.i) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'I' or 'i') end, colors.lightGray, colors.black)
  326. registerKey('ABC', 'o', 'o', 17, 1, nil, nil, function() os.queueEvent('key', keys.o) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'O' or 'o') end, colors.lightGray, colors.black)
  327. registerKey('ABC', 'p', 'p', 19, 1, nil, nil, function() os.queueEvent('key', keys.p) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'P' or 'p') end, colors.lightGray, colors.black)
  328.  
  329. -- Second row, ASCII keyboard
  330. registerKey('ABC', 'a', 'a', 2, 2, nil, nil, function() os.queueEvent('key', keys.a) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'A' or 'a') end, colors.lightGray, colors.black)
  331. registerKey('ABC', 's', 's', 4, 2, nil, nil, function() os.queueEvent('key', keys.s) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'S' or 's') end, colors.lightGray, colors.black)
  332. registerKey('ABC', 'd', 'd', 6, 2, nil, nil, function() os.queueEvent('key', keys.d) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'D' or 'd') end, colors.lightGray, colors.black)
  333. registerKey('ABC', 'f', 'f', 8, 2, nil, nil, function() os.queueEvent('key', keys.f) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'F' or 'f') end, colors.lightGray, colors.black)
  334. registerKey('ABC', 'g', 'g', 10, 2, nil, nil, function() os.queueEvent('key', keys.g) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'G' or 'g') end, colors.lightGray, colors.black)
  335. registerKey('ABC', 'h', 'h', 12, 2, nil, nil, function() os.queueEvent('key', keys.h) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'H' or 'h') end, colors.lightGray, colors.black)
  336. registerKey('ABC', 'j', 'j', 14, 2, nil, nil, function() os.queueEvent('key', keys.j) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'J' or 'j') end, colors.lightGray, colors.black)
  337. registerKey('ABC', 'k', 'k', 16, 2, nil, nil, function() os.queueEvent('key', keys.k) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'K' or 'k') end, colors.lightGray, colors.black)
  338. registerKey('ABC', 'l', 'l', 18, 2, nil, nil, function() os.queueEvent('key', keys.l) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'L' or 'l') end, colors.lightGray, colors.black)
  339.  
  340. -- Third row, ASCII keyboard
  341. registerKey('ABC', 'SF', '^ ', 1, 3, nil, nil, function() os.queueEvent('key', keys.leftShift) if os.clock() - shiftLastPressed < doubleClickSpeed and shiftPressed then capsLockPressed = not capsLockPressed elseif capsLockPressed then capsLockPressed = false else shiftPressed = not shiftPressed end shiftLastPressed = os.clock() end, colors.lightGray, colors.black)
  342. registerKey('ABC', 'z', 'z', 4, 3, nil, nil, function() os.queueEvent('key', keys.z) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'Z' or 'z') end, colors.lightGray, colors.black)
  343. registerKey('ABC', 'x', 'x', 6, 3, nil, nil, function() os.queueEvent('key', keys.x) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'X' or 'x') end, colors.lightGray, colors.black)
  344. registerKey('ABC', 'c', 'c', 8, 3, nil, nil, function() os.queueEvent('key', keys.c) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'C' or 'c') end, colors.lightGray, colors.black)
  345. registerKey('ABC', 'v', 'v', 10, 3, nil, nil, function() os.queueEvent('key', keys.v) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'V' or 'v') end, colors.lightGray, colors.black)
  346. registerKey('ABC', 'b', 'b', 12, 3, nil, nil, function() os.queueEvent('key', keys.b) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'B' or 'b') end, colors.lightGray, colors.black)
  347. registerKey('ABC', 'n', 'n', 14, 3, nil, nil, function() os.queueEvent('key', keys.n) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'N' or 'n') end, colors.lightGray, colors.black)
  348. registerKey('ABC', 'm', 'm', 16, 3, nil, nil, function() os.queueEvent('key', keys.m) os.queueEvent('char', (shiftPressed or capsLockPressed) and 'M' or 'm') end, colors.lightGray, colors.black)
  349. registerKey('ABC', 'BK', '<-', 18, 3, nil, nil, function() os.queueEvent('key', keys.backspace) end, colors.lightGray, colors.black)
  350.  
  351. -- Fourth row, ASCII keyboard
  352. registerKey('ABC', 'SB', ' space ', 5, 4, nil, nil, function() os.queueEvent('key', keys.space) os.queueEvent('char', ' ') end, colors.lightGray, colors.black)
  353. registerKey('ABC', 'EN', 'enter', 15, 4, nil, nil, function() os.queueEvent('key', keys.enter) end, colors.lightGray, colors.black)
  354. end
  355.  
  356. -- SECOND VIEW: 123
  357. do
  358. -- First row, Numbers
  359. registerKey('123', '1', '1', 1, 1, nil, nil, function() os.queueEvent('key', keys.one) os.queueEvent('char', '1') end, colors.lightGray, colors.black)
  360. registerKey('123', '2', '2', 3, 1, nil, nil, function() os.queueEvent('key', keys.two) os.queueEvent('char', '2') end, colors.lightGray, colors.black)
  361. registerKey('123', '3', '3', 5, 1, nil, nil, function() os.queueEvent('key', keys.three) os.queueEvent('char', '3') end, colors.lightGray, colors.black)
  362. registerKey('123', '4', '4', 7, 1, nil, nil, function() os.queueEvent('key', keys.four) os.queueEvent('char', '4') end, colors.lightGray, colors.black)
  363. registerKey('123', '5', '5', 9, 1, nil, nil, function() os.queueEvent('key', keys.five) os.queueEvent('char', '5') end, colors.lightGray, colors.black)
  364. registerKey('123', '6', '6', 11, 1, nil, nil, function() os.queueEvent('key', keys.six) os.queueEvent('char', '6') end, colors.lightGray, colors.black)
  365. registerKey('123', '7', '7', 13, 1, nil, nil, function() os.queueEvent('key', keys.seven) os.queueEvent('char', '7') end, colors.lightGray, colors.black)
  366. registerKey('123', '8', '8', 15, 1, nil, nil, function() os.queueEvent('key', keys.eight) os.queueEvent('char', '8') end, colors.lightGray, colors.black)
  367. registerKey('123', '9', '9', 17, 1, nil, nil, function() os.queueEvent('key', keys.nine) os.queueEvent('char', '9') end, colors.lightGray, colors.black)
  368. registerKey('123', '0', '0', 19, 1, nil, nil, function() os.queueEvent('key', keys.zero) os.queueEvent('char', '0') end, colors.lightGray, colors.black)
  369.  
  370. -- Second row, Symbols
  371. registerKey('123', 'minus', '-', 2, 2, nil, nil, function() os.queueEvent('key', keys.minus) os.queueEvent('char', '-') end, colors.lightGray, colors.black)
  372. registerKey('123', 'slash', '/', 4, 2, nil, nil, function() os.queueEvent('key', keys.slash) os.queueEvent('char', '/') end, colors.lightGray, colors.black)
  373. registerKey('123', 'colon', ':', 6, 2, nil, nil, function() os.queueEvent('key', keys.colon) os.queueEvent('char', ':') end, colors.lightGray, colors.black)
  374. registerKey('123', 'semicolon', ';', 8, 2, nil, nil, function() os.queueEvent('key', keys.colon) os.queueEvent('char', ';') end, colors.lightGray, colors.black)
  375. registerKey('123', 'lbracket', '(', 10, 2, nil, nil, function() os.queueEvent('key', keys.nine) os.queueEvent('char', '(') end, colors.lightGray, colors.black)
  376. registerKey('123', 'rbrakcet', ')', 12, 2, nil, nil, function() os.queueEvent('key', keys.zero) os.queueEvent('char', ')') end, colors.lightGray, colors.black)
  377. registerKey('123', 'dollars', '$', 14, 2, nil, nil, function() os.queueEvent('key', keys.four) os.queueEvent('char', '$') end, colors.lightGray, colors.black)
  378. registerKey('123', 'amp', '&', 16, 2, nil, nil, function() os.queueEvent('key', keys.seven) os.queueEvent('char', '&') end, colors.lightGray, colors.black)
  379. registerKey('123', 'at', '@', 18, 2, nil, nil, function() os.queueEvent('key', keys.two) os.queueEvent('char', '@') end, colors.lightGray, colors.black)
  380.  
  381. -- third row, Symbols
  382. registerKey('123', 'CYC_#+=', '#=', 1, 3, nil, nil, function() setActiveScreen('#+=') end, colors.lightGray, colors.black)
  383. registerKey('123', 'period', '.', 5, 3, nil, nil, function() os.queueEvent('key', keys.period) os.queueEvent('char', '.') end, colors.lightGray, colors.black)
  384. registerKey('123', 'comma', ',', 7, 3, nil, nil, function() os.queueEvent('key', keys.comma) os.queueEvent('char', ',') end, colors.lightGray, colors.black)
  385. registerKey('123', 'question', '?', 9, 3, nil, nil, function() os.queueEvent('key', keys.slash) os.queueEvent('char', '?') end, colors.lightGray, colors.black)
  386. registerKey('123', 'exclamation', '!', 11, 3, nil, nil, function() os.queueEvent('key', keys.one) os.queueEvent('char', '!') end, colors.lightGray, colors.black)
  387. registerKey('123', 'singleQuote', '\'', 13, 3, nil, nil, function() os.queueEvent('key', 0) os.queueEvent('char', '\'') end, colors.lightGray, colors.black)
  388. registerKey('123', 'quote', '\"', 15, 3, nil, nil, function() os.queueEvent('key', 0) os.queueEvent('char', '\"') end, colors.lightGray, colors.black)
  389. registerKey('123', 'BK', '<-', 18, 3, nil, nil, function() os.queueEvent('key', keys.backspace) end, colors.lightGray, colors.black)
  390.  
  391. -- Fourth row, Standard
  392. registerKey('123', 'SB', ' space ', 5, 4, nil, nil, function() os.queueEvent('key', keys.space) os.queueEvent('char', ' ') end, colors.lightGray, colors.black)
  393. registerKey('123', 'EN', 'enter', 15, 4, nil, nil, function() os.queueEvent('key', keys.enter) end, colors.lightGray, colors.black)
  394. end
  395.  
  396. -- THIRD VIEW: #+=
  397. do
  398. -- First row, Symbols
  399. registerKey('#+=', 'lsbrace', '[', 1, 1, nil, nil, function() os.queueEvent('key', keys.leftBracket) os.queueEvent('char', '[') end, colors.lightGray, colors.black)
  400. registerKey('#+=', 'rsbrace', ']', 3, 1, nil, nil, function() os.queueEvent('key', keys.rightBracket) os.queueEvent('char', ']') end, colors.lightGray, colors.black)
  401. registerKey('#+=', 'lcbrace', '{', 5, 1, nil, nil, function() os.queueEvent('key', keys.leftBracket) os.queueEvent('char', '{') end, colors.lightGray, colors.black)
  402. registerKey('#+=', 'rcbrace', '}', 7, 1, nil, nil, function() os.queueEvent('key', keys.rightBracket) os.queueEvent('char', '}') end, colors.lightGray, colors.black)
  403. registerKey('#+=', 'hash', '#', 9, 1, nil, nil, function() os.queueEvent('key', keys.three) os.queueEvent('char', '#') end, colors.lightGray, colors.black)
  404. registerKey('#+=', 'percent', '%', 11, 1, nil, nil, function() os.queueEvent('key', keys.five) os.queueEvent('char', '%') end, colors.lightGray, colors.black)
  405. registerKey('#+=', 'carrot', '^', 13, 1, nil, nil, function() os.queueEvent('key', keys.six) os.queueEvent('char', '^') end, colors.lightGray, colors.black)
  406. registerKey('#+=', 'asterisk', '*', 15, 1, nil, nil, function() os.queueEvent('key', keys.eight) os.queueEvent('char', '*') end, colors.lightGray, colors.black)
  407. registerKey('#+=', 'plus', '+', 17, 1, nil, nil, function() os.queueEvent('key', keys.equals) os.queueEvent('char', '+') end, colors.lightGray, colors.black)
  408. registerKey('#+=', 'equals', '=', 19, 1, nil, nil, function() os.queueEvent('key', keys.equals) os.queueEvent('char', '=') end, colors.lightGray, colors.black)
  409.  
  410. -- Second row, Symbols
  411. registerKey('#+=', 'score', '_', 2, 2, nil, nil, function() os.queueEvent('key', keys.minus) os.queueEvent('char', '_') end, colors.lightGray, colors.black)
  412. registerKey('#+=', 'backslash', '\\', 4, 2, nil, nil, function() os.queueEvent('key', keys.backslash) os.queueEvent('char', '\\') end, colors.lightGray, colors.black)
  413. registerKey('#+=', 'bar', '|', 6, 2, nil, nil, function() os.queueEvent('key', keys.backslash) os.queueEvent('char', '|') end, colors.lightGray, colors.black)
  414. registerKey('#+=', 'tild', '~', 8, 2, nil, nil, function() os.queueEvent('key', 0) os.queueEvent('char', '~') end, colors.lightGray, colors.black)
  415. registerKey('#+=', 'lt', '<', 10, 2, nil, nil, function() os.queueEvent('key', keys.comma) os.queueEvent('char', '<') end, colors.lightGray, colors.black)
  416. registerKey('#+=', 'gt', '>', 12, 2, nil, nil, function() os.queueEvent('key', keys.period) os.queueEvent('char', '>') end, colors.lightGray, colors.black)
  417. registerKey('#+=', 'dollars', '$', 14, 2, nil, nil, function() os.queueEvent('key', keys.four) os.queueEvent('char', '$') end, colors.lightGray, colors.black)
  418. registerKey('#+=', 'amp', '&', 16, 2, nil, nil, function() os.queueEvent('key', keys.seven) os.queueEvent('char', '&') end, colors.lightGray, colors.black)
  419. registerKey('#+=', 'at', '@', 18, 2, nil, nil, function() os.queueEvent('key', keys.two) os.queueEvent('char', '@') end, colors.lightGray, colors.black)
  420.  
  421. -- third row, Symbols
  422. registerKey('#+=', 'CYC_123', '12', 1, 3, nil, nil, function() setActiveScreen('123') end, colors.lightGray, colors.black)
  423. registerKey('#+=', 'period', '.', 5, 3, nil, nil, function() os.queueEvent('key', keys.period) os.queueEvent('char', '.') end, colors.lightGray, colors.black)
  424. registerKey('#+=', 'comma', ',', 7, 3, nil, nil, function() os.queueEvent('key', keys.comma) os.queueEvent('char', ',') end, colors.lightGray, colors.black)
  425. registerKey('#+=', 'question', '?', 9, 3, nil, nil, function() os.queueEvent('key', keys.slash) os.queueEvent('char', '?') end, colors.lightGray, colors.black)
  426. registerKey('#+=', 'exclamation', '!', 11, 3, nil, nil, function() os.queueEvent('key', keys.one) os.queueEvent('char', '!') end, colors.lightGray, colors.black)
  427. registerKey('#+=', 'singleQuote', '\'', 13, 3, nil, nil, function() os.queueEvent('key', 0) os.queueEvent('char', '\'') end, colors.lightGray, colors.black)
  428. registerKey('#+=', 'quote', '\"', 15, 3, nil, nil, function() os.queueEvent('key', 0) os.queueEvent('char', '\"') end, colors.lightGray, colors.black)
  429. registerKey('#+=', 'BK', '<-', 18, 3, nil, nil, function() os.queueEvent('key', keys.backspace) end, colors.lightGray, colors.black)
  430.  
  431. -- Fourth row, Standard
  432. registerKey('#+=', 'SP_ABC', 'ABC', 1, 4, nil, nil, function() setActiveScreen('ABC') end, colors.lightGray, colors.black)
  433. registerKey('#+=', 'SB', ' space ', 5, 4, nil, nil, function() os.queueEvent('key', keys.space) os.queueEvent('char', ' ') end, colors.lightGray, colors.black)
  434. registerKey('#+=', 'EN', 'enter', 15, 4, nil, nil, function() os.queueEvent('key', keys.enter) end, colors.lightGray, colors.black)
  435. end
  436.  
  437. startCoroutine()
  438. end
  439.  
  440. --[[
  441. q w e r t y u i o p
  442. a s d f g h j k l
  443. ^ z x c v b n m <-
  444. 123 space enter
  445.  
  446.  
  447.  
  448. 1 2 3 4 5 6 7 8 9 0
  449. - / : ; ( ) $ & @ "
  450. #+= . , ? ! ' <-
  451. ABC space enter
  452.  
  453.  
  454.  
  455. [ ] { } # % ^ * + =
  456. _ \ | ~ < > $ & @ "
  457. 123 . , ? ! ' <-
  458. ABC space enter
  459. ]]
Add Comment
Please, Sign In to add comment