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
1
Wait if there will be input in 10 seconds and then move on
Started by abouttabs, Jul 10 2013 05:04 PM
6 replies to this topic
#1
Posted 10 July 2013 - 05:04 PM
#2
Posted 10 July 2013 - 05: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
#3
Posted 10 July 2013 - 05:10 PM
Thank you so much sir.. I had no idea about such fancy things :-)
#4
Posted 10 July 2013 - 05:12 PM
No problem. If you encounter any issues let me know
#5
Posted 10 July 2013 - 05:14 PM
thank you
#6
Posted 17 August 2013 - 11:29 PM
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
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
#7
Posted 19 August 2013 - 01: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:
if you uncomment the other line with the print it will say "you pressed a key" everytime you press a key
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
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users