in reply to GUI-like behavior
It would probably help if you were at least a little less vague about what you are doing. What the program will be trying to do when a keypress comes in can make a huge difference in what approaches make sense. Also, more details on what type of user interface you would like after you press the key would help.
But my first idea is to have a subroutine that does a non-blocking read (or peek) to see if there is any input (probably via Term::ReadKey) and if there is none, then it immediately returns. If there is some, then it prompts for what you want to do.
Then you sprinkle calls to this subroutine all over your code, making sure that there aren't any long-running sections where the routine will never be called.
Depending on what your code is doing, this sprinkle might be reduced to just a single call.
You could also teach this routine to be smart enough to track how long it was since the last time it was called and notify you if it ever takes more than Xms between calls so that you can know that more sprinkling is required. (and in such cases report the call stack to you so you can figure out what just ran that took so long w/o sprinkles)
- tye
|
|---|