columna1

Monitor keypad

Jun 19th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. margin = 1
  2. mon = peripheral.wrap("right")
  3. mon.setTextScale(1)
  4. shift = true
  5. cur = false
  6. mon.clear()
  7. password = "Pass!"
  8. on = true
  9. xx = 1
  10. yy = 7
  11. keys = {
  12. {"1","2","3","4","5","6","7","8","9","0","-","="," "," "},
  13. {"q","w","e","r","t","y","u","i","o","p","[","]"," ","S"},
  14. {"a","s","d","f","g","h","j","k","l",";","'"," "," ","X"},
  15. {"z","x","c","v","b","n","m",",",".","/"," ","<",">","_"}
  16. }
  17. keysShift = {
  18. {"!","@","#","$","%","^","&","*","(",")","_","+"," "," "},
  19. {"Q","W","E","R","T","Y","U","I","O","P","{","}","|","s"},
  20. {"A","S","D","F","G","H","J","K","L",":"," "," "," ","x"},
  21. {"Z","X","C","V","B","N","M"," "," ","?"," ","<",">","_"}
  22. }
  23. temppass = ""
  24. function prints(offx,offy,tabl)
  25.  -- print("print function called")
  26.   for i = 1,#tabl do
  27.     for j = 1,#tabl[i] do
  28.       mon.setCursorPos(offy+j,offx+i)
  29.       mon.write(tabl[i][j])
  30.       mon.setCursorPos(xx,yy)
  31.     end
  32.   end
  33. end
  34. function win()
  35.   on = false
  36.   printreadout(6,8,"Pass")
  37. end
  38. function lose()
  39.   on = false
  40.   printreadout(6,8,"Fail")
  41. end
  42. function pass(str)
  43.   if str == password then
  44.     win()
  45.   else
  46.     lose()
  47.   end
  48. end
  49. function printreadout(x,y,str)
  50.   mon.setCursorPos(x,y)
  51.   mon.write(str)
  52.   xx = #str+1
  53.   yy = y
  54. end
  55. function printtable(table)
  56.   for i = 1,#table do
  57.     print(table[i])
  58.   end
  59. end
  60. function detect(offx,offy,tabl)
  61.   event,side,x,y = os.pullEvent("monitor_touch")
  62.   x = x - offx
  63.   y = y - offy
  64.   height = #tabl+offy
  65.   width = #tabl[1]+offx
  66.   --[[
  67.   print(x)
  68.   print(y)
  69.   print(offx)
  70.   print(offy)
  71.   print(x-offx)
  72.   print(y-offy)
  73.   ]]--
  74.   if x > 0 and y < height and y > 0 and x < width then
  75.     letter = tabl[y][x]
  76.     if letter == ">" then
  77.       pass(temppass)
  78.     elseif letter == "X" and shift == false or letter == "x" and shift == true then
  79.       --clear enter (clear the table 'temppass')
  80.       printreadout(margin,height+2,"                          ")
  81.       temppass = ""
  82.     elseif letter == "_" then
  83.       temppass = temppass.." "
  84.     elseif letter == "<" then
  85.       temppass = temppass:sub(0,#temppass-1)
  86.       printreadout(margin,height+2,"                           ")
  87.       printreadout(margin,height+2,temppass)
  88.     elseif letter == " " then
  89.      
  90.     elseif letter == "S" and shift == false or letter == "s" and shift == true then
  91.       cur = not cur
  92.     else
  93.       temppass = temppass..letter
  94.     end
  95.   end
  96. end
  97. height = #keys
  98. mon.setCursorPos(margin,height+2)
  99. mon.setCursorBlink(true)
  100. while on do
  101. if shift == true and cur == false then
  102.   shift = false
  103.   prints(margin,2,keys)
  104. elseif shift == false and cur == true then
  105.   shift = true
  106.   prints(margin,2,keysShift)
  107. end
  108. if shift == false then
  109.   detect(2,margin,keys)
  110. elseif shift == true then
  111.   detect(2,margin,keysShift)
  112. end
  113. printreadout(margin,height+2,temppass)
  114. end
  115. mon.setCursorBlink(false)
Advertisement
Add Comment
Please, Sign In to add comment