How to read a single character in D language?

Adam D Ruppe destructionator at gmail.com
Fri Nov 19 18:01:57 UTC 2021


On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote:
> Let's say I want to write a simple program that asks for an 
> input of a single character.
> After pressing a single key on a keyboard, the character is 
> printed out and the program  should stop.

This is platform specific. About 10 lines of code for a minimum 
implementation per OS, but if you don't wanna do it that way my 
library has a function for it with a prepackaged sample:

http://arsd-official.dpldocs.info/arsd.terminal.html#single-key

that's arsd-official:terminal on dub or you can grab the file 
from my github repo.

I guess you could view my source to see the impl but I don't feel 
like pulling it out right now.


More information about the Digitalmars-d-learn mailing list