【问题标题】:Read a single char from stdin without pressing enter从标准输入读取单个字符而不按回车
【发布时间】:2017-02-19 05:07:29
【问题描述】:

如何在不按回车键的情况下从控制台读取单个字符?

在 ruby​​ 中我只会使用:

require 'io/console'
input = STDIN.getch

【问题讨论】:

    标签: crystal-lang


    【解决方案1】:

    试试这个:

    char = STDIN.raw &.read_char
    p char
    

    【讨论】:

    • 是否有 STDIN.ready? 的等价物?当我阅读 Meta/Alt 字符或 Shifted-Fn 键时,我会在 STDIN.ready? 时继续阅读,并在未准备好时返回收集的键。
    猜你喜欢
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多