See if this helps, especially the State Machine part:
In this blog Nick shows how to do multiple things at once, explaining blocking and non-blocking code in the process:
What you need to do is not a whole lot more than the State Machine example. You may need to look for more than single characters but the principle is the same and btw, the extent of what you are doing does qualify as "work" and not some quick little bit of code. Spend time planning every step you need to do before you write a line.