简体   繁体   English

如何在不等待按 ENTER 的情况下从 stdin 中仅读取一个字符?

[英]How to read only one character from stdin without waiting for pressing ENTER?

I have CLI implementation for my VisualWorks application.我的 VisualWorks 应用程序有 CLI 实现。 There is "IOAccessor defaultClass stdin" and I want to read one character without waiting for user enter press.有“IOAccessor defaultClass stdin”,我想在不等待用户输入按下的情况下读取一个字符。 It is possible?有可能的?

in C language there is function like getCh ...在 C 语言中有像 getCh 这样的函数......

This is not a problem of the language: also the C-language getchar() will have to wait.这不是语言的问题:C 语言 getchar() 也必须等待。 It is a matter of the underlying Operating System's tty-code.这是底层操作系统的 tty 代码的问题。 On UNIX (eg. Linux), you'd have to change the tty-characteristics to unbuffered, using an stty (old-style) or ioctl call.在 UNIX(例如 Linux)上,您必须使用 stty(旧式)或 ioctl 调用将 tty 特征更改为无缓冲。 Under other OSs, similar system calls do similar things.在其他操作系统下,类似的系统调用做类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM