I need a way for a user to stop the current sub-script they're running and go back to the menu script that called the sub-script.
Here's an example:
There's a menu script that shows something like this:
1. Hire
2. Re-Hire
3. Termination
etc
Please choose a number:
If they choose 1, it goes to the hire script which prompts for name, office, title, etc like the following:
write-host "First Name: " -fore yellow -nonewline $fname = read-host write-host "Last Name: " -fore yellow -nonewline $lname = read-host write-host "Password: " -fore yellow -nonewline $pass = read-host write-host "Department: " -fore yellow -nonewline $dept = read-host write-host "Title: " -fore yellow -nonewline $title = read-host write-host "Manager (username): " -fore yellow -nonewline $manager = read-host
So then let's say the user is in this script and doesn't want to do that right now and wants to get back to the main menu. Instead of having to press Ctrl-C and close the script and re-open it, is there a way to catch a certain key press and then exit the sub-script back to the menu?
Could I put something like an if statement on each response that checks whether what the person entered was the ESC key or Ctrl-X or something along those lines? Like:
write-host "First Name: " -fore yellow -nonewline $fname = read-host if ($fname -eq "Ctrl-X") { .\menu.ps1 } # I have tried different versions of this, and can't get it to work ...
Or could I wrap the whole thing in some type of while statement that says "while this key hasn't been pressed, do the following" but as soon as that key (ESC) or key combination (Ctrl-X) has been pressed, then go back to the menu?
Hope I'm making this clear...