View difference between Paste ID: seyTaa0k and cxH2chZx
SHOW: | | - or go back to the newest paste.
1
local characters = {"`","1","2","3","4","5","6","7","8","9","0","-","=",
2
  "q","w","e","r","t","y","u","i","o","p","[","]","\\",
3
  "a","s","d","f","g","h","j","k","l",";","'",
4
  "z","x","c","v","b","n","m",",",".","/",
5
  "~","!","@","#","$","%","^","&","*","(",")","_","+",
6
  "Q","W","E","R","T","Y","U","I","O","P","{","}","|",
7
  "A","S","D","F","G","H","J","K","L",":",'"',
8
  "Z","X","C","V","B","N","M","<",">","?"
9
}
10
local disabled = {}
11
12
local digitnum = 18
13
14
while true do
15
  local code = ""
16
  term.clear()
17
  term.setCursorPos(1,1)
18
  term.setTextColor(colors.white)
19
  if #characters > 0 then
20
    for h=1,#characters do
21
      write(characters[h]..", ")
22
    end
23
  end
24
  
25
  term.setTextColor(colors.gray)
26
  if #disabled > 0 then
27
    for h=1,#disabled do
28
      write(disabled[h]..", ")
29
    end
30
  end
31
  term.setTextColor(colors.white)
32
  print("\n")
33
  print("Press any key to enable/disable the character or click on any option below.\n")
34
  
35
  print("Digits: <"..digitnum..">")
36
  print("Generate Code")
37
  print("Exit\n")
38
  
39
  local event, button, xPos, yPos = os.pullEvent()
40
  if event == "char" then
41
    for g=1,94 do
42
      if button == characters[g] then
43
        table.insert(disabled, 1, characters[g])
44
        table.remove(characters, g)
45
      elseif button == disabled[g] then
46
        table.insert(characters, 1, disabled[g])
47
        table.remove(disabled, g)
48
      end
49
    end
50
  
51
  elseif event == "key" then
52
    if button == 203 then
53
      if digitnum > 1 then
54
        digitnum = digitnum - 1
55
      end
56
    elseif button == 205 then
57
      digitnum = digitnum + 1
58
    end
59
  elseif event == "mouse_click" then
60
    if xPos >= 1 and xPos <= 13 and yPos == 12 then
61
      if #characters > 0 then
62
        for i=1,digitnum do
63
          local t = math.ceil(math.random(1,#characters))
64
          code = code..characters[t]
65
        end
66
67
        print(code)
68
        
69
      else
70
        print("Can't generate a code. All characters are disabled.")
71
      end
72
      
73
      print("\nPress any button to continue.")
74-
      local event = os.pullEvent()
74+
      local event = os.pullEvent("key")
75
      
76
    elseif xPos >= 1 and xPos <= 4 and yPos == 13 then
77
      break
78
    elseif xPos == 9 and yPos == 11 then
79
      if digitnum > 1 then
80
        digitnum = digitnum - 1
81
      end
82
    elseif xPos == 9+string.len(tostring(digitnum))+1 and yPos == 11 then
83
      digitnum = digitnum + 1
84
    end
85
  end
86
end
87
88
shell.run("clear")