11 posts
Posted 10 July 2013 - 06:04 PM
Hi guys
I am trying to figure out if there is a way to make program wait for input (probably keystroke) for set amount of time and then move on.
I wat it as user way to shut down resume of program that is taking state from another file and would run tindefinitely if no option to reset (like this) was awailable.
I would gratly appreciate any help on this topic, either this solution or any other that would work.
Thank you for your time and effort.
Sincerely Abouttabs
1190 posts
Location
RHIT
Posted 10 July 2013 - 06:08 PM
You can use timers to do this:
local timer = os.startTimer(10) --#The interval that you would like to wait
while true do
local event, result = os.pullEvent()
if event=="timer" and timer==result then --#If a timer event is pulled and its ID matches the one returned by startTimer
break --#Break out of the loop and continue with code execution
elseif event=="key" then
if result == keys.enter then --#They pressed a key under the 10 second interval.
--#Do stuff
end
end
end
11 posts
Posted 10 July 2013 - 06:10 PM
Thank you so much sir.. I had no idea about such fancy things :-)
1190 posts
Location
RHIT
Posted 10 July 2013 - 06:12 PM
No problem. If you encounter any issues let me know :)/>
11 posts
Posted 10 July 2013 - 06:14 PM
thank you
4 posts
Posted 18 August 2013 - 12:29 AM
This is great but it only works if you press 'enter'.
I noticed if you remove line 7 it works for any key but it prints what the user presses.
Is there a way to modify the program to work for any key without leaving anything behind?
Thanks heaps, Yardking42
199 posts
Location
Switzerland
Posted 19 August 2013 - 02:53 PM
edit: maybe you did not remove line 7 correctly. you have to remove the end for the if statement also. else it will not work.
like this nothing is printed:
local timer = os.startTimer(10) --#The interval that you would like to wait
while true do
local event, result = os.pullEvent()
if event=="timer" and timer==result then --#If a timer event is pulled and its ID matches the one returned by startTimer
break --#Break out of the loop and continue with code execution
elseif event=="key" then
--print("you pressed a key")
end
end
if you uncomment the other line with the print it will say "you pressed a key" everytime you press a key :D/>