Advertisement
CaptainSpaceCat

Keyboard

May 31st, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. if not fs.exists("button") then
  2.   shell.run("pastebin get LP2ZQ5dG button")
  3. end
  4. term.setBackgroundColor(colors.black)
  5. term.clear()
  6. term.setBackgroundColor(colors.white)
  7. local w, h = term.getSize()
  8. for i = h - 4, h do
  9.   term.setCursorPos(1, i)
  10.   term.clearLine()
  11. end
  12. os.loadAPI("button")
  13. keys = {"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"}
  14.  
  15. local vKeys = {}
  16. local cKeys = {}
  17. local keyX = 1
  18. local keyY = h - 4
  19. for i, v in pairs(keys) do
  20.   if v == "A" or v == "Z" then
  21.     keyY = keyY + 2
  22.     keyX = 1
  23.   end
  24.   vKeys[v] = button.Button:new(v, keyX, keyY, keyX, keyY, 8, 1, 8, 9)
  25.   keyX = keyX + math.floor(w / 11)
  26. end
  27. Delete = button.Button:new("Delete", w - 5, h - 4, w, h - 4, 8, 1, 8, 9)
  28. Enter = button.Button:new("Enter", w - 4, h - 2, w, h - 2, 8, 1, 8, 9)
  29. Shift = button.Button:new("Shift", w - 4, h, w, h, 8, 1, 8, 9)
  30.  
  31. local nextCap = false
  32. local xPos = 1
  33. local yPos = 1
  34. while true do
  35.   Delete:display()
  36.   Enter:display()
  37.   Shift:display()
  38.   for i, v in pairs(vKeys) do
  39.     v:display()
  40.   end
  41.   button.getClick()
  42.   for i, v in pairs(vKeys) do
  43.     if v:check() then
  44.       term.setCursorPos(xPos, yPos)
  45.       term.setBackgroundColor(colors.black)
  46.       term.setTextColor(colors.white)
  47.       if nextCap then
  48.         term.write(i)
  49.       else
  50.         term.write(string.lower(i))
  51.       end
  52.       xPos = xPos + 1
  53.     end
  54.   end
  55.   if xPos > w then
  56.     xPos = 1
  57.     yPos = yPos + 1
  58.   end
  59.   if Delete:check() then
  60.     if xPos == 1 then
  61.       xPos = w
  62.       yPos = yPos - 1
  63.     else
  64.       xPos = xPos - 1
  65.     end
  66.     term.setCursorPos(xPos, yPos)
  67.     term.setBackgroundColor(colors.black)
  68.     term.setTextColor(colors.white)
  69.     term.write(" ")
  70.   end
  71.   if Enter:check() then
  72.     yPos = yPos + 1
  73.     xPos = 1
  74.   end
  75.   if Shift:check() then
  76.     nextCap = true
  77.   else
  78.     nextCap = false
  79.   end
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement