tcl暂停&等待按键继续 [英] tcl pause & waiting for key pressed to continue

查看:983
本文介绍了tcl暂停&等待按键继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在tcl中寻找一种方法来暂停脚本(例如,在某些带有"puts"的输出之后)并等待用户按下某个键,然后继续输出其余文本.

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.

推荐答案

如果您正在使用 stty

With gratitude to Hai Vu's answer, if you're on a unix-like system with stty

proc anykey {{msg "Hit any key: "}} {
    set stty_settings [exec stty -g]
    exec stty raw -echo
    puts -nonewline $msg
    flush stdout
    read stdin 1
    exec stty $stty_settings
    puts ""
}
puts 1
anykey
puts 2

链接到有关Tcl Wiki的详尽讨论:使用Tcl从键盘读取单个字符

Link to thorough discussion on Tcl wiki: Reading a single character from the keyboard using Tcl

这篇关于tcl暂停&等待按键继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆