python 设置按键停止脚本
1、首先,按回车键退出。#coding=utf-8raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))

3、# 获取标准输入的描述符fd = sys.stdin.fileno()# 获取标准输入(终端)的设置old_ttyinfo = termios.tcgetattr烫喇霰嘴(fd)# 配置终端new_ttyinfo = old_ttyinfo[:]# 使用非规范模式(索引3是c_lflag 也就是本地模式)new_ttyinfo[3] &= ~termios.ICANON# 关闭回显(输入不会被显示)new_ttyinfo[3] &= ~termios.ECHO

5、# 还原终端设置termios.tcsetattr(fd, termios.TCSANOW, old_ttyinfo)if __name__ == "__main__":press_any_key_exit("按任意键继续...")press_any_key_exit("按任意键退出...")

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:60
阅读量:21
阅读量:76
阅读量:54
阅读量:55