Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9596
Posted: 03:19pm 03 Mar 2013
Copy link to clipboard
Print this post
Hi folks.
My menu is coming along nicely, but I have a "SYSTEM MENU", which allows changes to the parameters of the system. Normally, "Joe Bloggs" does not need to be in here, but techs will need to be, so I decided to protect the menu with a simple password embedded in the code.
That is working fine. If code is correct, it goes to the system menu, if the code is wrong, it just goes back to the main menu.
However, is there any way to make the line input command timeout after, say, 3 seconds, and if no keys are pressed in this time period, then the code goes back to the main menu automatically?
Line input is waiting for the user to press [CR], which is fine, but if they never press any key(as they don't know the password), then they will never get back to the main menu.
Hopefully, you can see what I mean.
EDIT: Working on an idea involving inkey$ and the timer command inside a loop.
Edited by Grogster 2013-03-05Smoke makes things work. When the smoke gets out, it stops!
shoebuckle Senior Member Joined: 21/01/2012 Location: AustraliaPosts: 189
Posted: 03:35pm 03 Mar 2013
Copy link to clipboard
Print this post
Grogster, yes it can be done using the Timer. For instance:
Do
Print "Press a Key"
Timer=0
Do
a$=Inkey$
Loop until Timer=3000 or a$<>""
If a$<>"" then print a$
Loop
Cheers,
Hugh
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209
Posted: 07:18am 04 Mar 2013
Copy link to clipboard
Print this post
you can collect the inkey$ values by appending them to a string.
Everytime a key is pressed and it is not enter you reset the timeout timer.
If it is enter you jump out of the loop and check against a stored password.
If the timeout occurs you jump out the loop and return to the menu.
You can keep it simple by accepting all keys and not do anything special with tab, space, backspace, delete etc.
You can make this into a function that accepts a timeout value and returns a string.
Edited by TZAdvantage 2013-03-05Microblocks. Build with logic.
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9596
Posted: 11:57am 04 Mar 2013
Copy link to clipboard
Print this post
Thanks for the help, guys.
I will have a play around with some more loops. Smoke makes things work. When the smoke gets out, it stops!