ecco7777

CC typer

Dec 22nd, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. -- typist.lua
  2. -- Realistic terminal typing for ComputerCraft 1.7
  3.  
  4. -- ===== CONFIG =====
  5. local BASE_DELAY  = 0.05
  6. local VARIANCE    = 0.04
  7. local PUNCT_DELAY = 0.12
  8. local LINE_DELAY  = 0.25
  9.  
  10. -- ===== SETUP =====
  11. local args = { ... }
  12. if not args[1] then
  13.     print("Usage: typist <file>")
  14.     return
  15. end
  16.  
  17. local filename = args[1]
  18. if not fs.exists(filename) then
  19.     print("File not found.")
  20.     return
  21. end
  22.  
  23. local file = fs.open(filename, "r")
  24. if not file then
  25.     print("Could not open file.")
  26.     return
  27. end
  28.  
  29. math.randomseed(os.time())
  30.  
  31. local function humanSleep(base)
  32.     local d = base + (math.random() * VARIANCE * 2 - VARIANCE)
  33.     if d < 0 then d = 0 end
  34.     sleep(d)
  35. end
  36.  
  37. -- ===== TERMINAL HELPERS =====
  38. local function advanceCursor()
  39.     local x, y = term.getCursorPos()
  40.     local w, h = term.getSize()
  41.  
  42.     if x > w then
  43.         x = 1
  44.         y = y + 1
  45.     end
  46.  
  47.     if y > h then
  48.         term.scroll(1)
  49.         y = h
  50.     end
  51.  
  52.     term.setCursorPos(x, y)
  53. end
  54.  
  55. local function typeChar(c)
  56.     term.write(c)
  57.     advanceCursor()
  58.  
  59.     if c:match("[%.%,%!%?]") then
  60.         humanSleep(PUNCT_DELAY)
  61.     else
  62.         humanSleep(BASE_DELAY)
  63.     end
  64. end
  65.  
  66. local function newLine()
  67.     local _, y = term.getCursorPos()
  68.     local _, h = term.getSize()
  69.  
  70.     if y >= h then
  71.         term.scroll(1)
  72.         term.setCursorPos(1, h)
  73.     else
  74.         term.setCursorPos(1, y + 1)
  75.     end
  76.  
  77.     sleep(LINE_DELAY)
  78. end
  79.  
  80. -- ===== MAIN LOOP =====
  81. while true do
  82.     local line = file.readLine()
  83.     if not line then break end
  84.  
  85.     for i = 1, #line do
  86.         typeChar(line:sub(i, i))
  87.     end
  88.  
  89.     newLine()
  90. end
  91.  
  92. file.close()
  93.  
Advertisement
Add Comment
Please, Sign In to add comment