简体   繁体   中英

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

I have CLI implementation for my VisualWorks application. There is "IOAccessor defaultClass stdin" and I want to read one character without waiting for user enter press. It is possible?

in C language there is function like getCh ...

This is not a problem of the language: also the C-language getchar() will have to wait. It is a matter of the underlying Operating System's tty-code. On UNIX (eg. Linux), you'd have to change the tty-characteristics to unbuffered, using an stty (old-style) or ioctl call. Under other OSs, similar system calls do similar things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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