This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
luza's profile picture

Masked Input Api

Started by luza, 22 February 2012 - 03:12 PM
luza #1
Posted 22 February 2012 - 04:12 PM
DERP DERP. I JUT REALISED read("*") DOES THE SAME…







function maskedInput(pReplace)
local replace = pReplace or "*"
local x,y = term.getCursorPos()
local input = {}
term.setCursorBlink(true)

while true do
    local event, p1 = os.pullEvent()
    if event == "char" then
	    input[#input+1]=p1
	    write(replace)
    elseif event == "key" then
	    if p1 == 28 then --enter
		    break
	    elseif p1 == 14 then --backspace
		    table.remove(input)
		    term.setCursorPos(x+#input, y)
		    write(" ")
		    term.setCursorPos(x+#input, y)
	    end
    end
end
 print("")
term.setCursorBlink(false)
return table.concat(input)
end



wilcomega #2
Posted 23 February 2012 - 07:29 PM
^_^/>/>