tcl pause & waiting for key pressed to continue

user2669068 picture user2669068 · Sep 25, 2013 · Viewed 15.2k times · Source

I'm looking for a way in tcl to pause the script (for example after some outputs with "puts") and wait for a key pressed from the user before continuing to output the remaining text.

Answer

Hai Vu picture Hai Vu · Sep 25, 2013

You just use gets to read from stdin:

proc pause {{message "Hit Enter to continue ==> "}} {
    puts -nonewline $message
    flush stdout
    gets stdin
}

pause "Hurry, hit enter: "; # Sample usage 1
pause;                      # Sample usage 2, use default message