Ok, So Im Attempting To Make A "Wilson Bot". Just Something That Lets You Have A Few Quick Programs, Like Chat Or Reboot, At The Press Of A Key .
Example:
local ev, param1, param2 = os.pullEvent()
if param1 == 18 then --e Key
print("Exiting Wilson Program . . .")
sleep(0.5)
shell.run("clear")
elseif param1 == 25 then --p Key
term.write("Program: ")
input = read()
shell.run(input)
else
print("Unrecognized Command. Hit 'h' If You Need Help")
end
Its Working Great So Far, However If You Press p It Will Execute The term.write() But Will Keep The p Key On Screen.
For Example It Will Print This:
Program: p
Anyone Know How To Delete That p Without The Entire Screen Being Cleared?
0
How To Clear USER Input
Started by Zenon, Jun 27 2015 07:21 PM
2 replies to this topic
#1
Posted 27 June 2015 - 07:21 PM
#2
Posted 27 June 2015 - 07:45 PM
Two events are generated when a person presses, for example, 'p'. One event is the key event (which you are using). The second event is the 'char' event, which the read() function uses. You pull the key event, but leave the char event in queue, where it's pulled by the read() function. Presumably, the user can simply hit backspace to delete the p.
Of course, you don't want the p appearing in the first place, which is easy.
Of course, you don't want the p appearing in the first place, which is easy.
local ev, param1, param2 = os.pullEvent() if param1 == 18 then --e Key print("Exiting Wilson Program . . .") sleep(0.5) shell.run("clear") elseif param1 == 25 then --p Key term.write("Program: ") os.pullEvent( "char" ) --#get rid of the char event still in queue input = read() shell.run(input) else print("Unrecognized Command. Hit 'h' If You Need Help") end
#3
Posted 27 June 2015 - 08:05 PM
Wow, Thanks! Didnt Think It Would Be That Easy Haha.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users