How to read a single character in D language?

Imperatorn johan_forsberg_86 at hotmail.com
Fri Nov 19 22:38:38 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.

If you want to test on Windows you can do this:

```d
// conio.h
extern (C) int _getch();
```

Like for demonstration purposes:
```d
writeln("Press a button...");
int a = _getch();
writeln("You pressed ", a);
```

That should be unbuffered.


More information about the Digitalmars-d-learn mailing list