0
[Solved] Keyboard Inputs
Started by TipTricky, Jan 18 2013 06:26 PM
9 replies to this topic
#1
Posted 18 January 2013 - 06:26 PM
I was wondering how you get keyboard inputs in a program. Like lets say i ran a program i made that needs some one to type in a password to get it to run how would i get the key board inputs.
#2
Posted 18 January 2013 - 06:35 PM
There are a couple of ways, to just capture user input try read() or io.read()
write("Enter Password: ") local password = read("*") -- the "*" makes the text appear as * on the screen
#3
Posted 18 January 2013 - 06:45 PM
Ok so is io.read() better to use in this case or os.pullEvent()?
io.read() seems simpler than os.pullEvent() correct?
io.read() seems simpler than os.pullEvent() correct?
#4
Posted 18 January 2013 - 06:46 PM
it is much simpler. however it will only read ascii chars. if you wish to read other keys such as enter or control you will need to use an event loop.
#5
Posted 18 January 2013 - 06:50 PM
Thank you for the help read() work perfectly.
#6
Posted 18 January 2013 - 11:19 PM
you could do on an if statement:
x = read("*") if x == "passcode" then --code
#7
Posted 19 January 2013 - 12:48 AM
write("Password: ") local input = read("*") local pass = "123" --Password if input == pass then print("Welcome") elseif input ~= pass then print("Wrong password") else print("Unknown error") end
#8
Posted 20 January 2013 - 02:11 AM
(taken down by owner)
#9
Posted 20 January 2013 - 02:19 AM
FreePaidRemake, on 19 January 2013 - 12:48 AM, said:
write("Password: ") local input = read("*") local pass = "123" --Password if input == pass then print("Welcome") elseif input ~= pass then print("Wrong password") else print("Unknown error") end
if input == pass then -- code when they are equivalent else -- code when that are not equivalent endAlso you may want to surround the entire thing with an infinite while loop so that the program will not exit after they have pressed enter...
while true do -- program code here end
dan14941, on 20 January 2013 - 02:11 AM, said:
Or just use my lock it has custom pass input
#10
Posted 20 January 2013 - 12:01 PM
TheOriginalBIT, on 20 January 2013 - 02:19 AM, said:
FreePaidRemake, on 19 January 2013 - 12:48 AM, said:
write("Password: ") local input = read("*") local pass = "123" --Password if input == pass then print("Welcome") elseif input ~= pass then print("Wrong password") else print("Unknown error") end
if input == pass then -- code when they are equivalent else -- code when that are not equivalent endAlso you may want to surround the entire thing with an infinite while loop so that the program will not exit after they have pressed enter...
while true do -- program code here end
dan14941, on 20 January 2013 - 02:11 AM, said:
Or just use my lock it has custom pass input
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users