How to read a single character in D language?

Alexey animuspexus at protonmail.com
Wed Nov 24 05:22:29 UTC 2021


On Wednesday, 24 November 2021 at 04:51:03 UTC, Alexey wrote:
> On Wednesday, 24 November 2021 at 04:48:46 UTC, Alexey wrote:

oh, also I completely missed what you need it to work without 
Enter key presses. so here is fixed version

```D
import std.stdio;

import core.sys.posix.termios;

void main()
{
	termios input_settings;
	
	tcgetattr(stdin.fileno, &input_settings);
	input_settings.c_lflag &= ~ICANON;
	tcsetattr(stdin.fileno, TCSANOW, &input_settings);
	
	while (true)
	{
		char c;
		stdin.readf("%c", &c);
		
		writefln("\n%c (0x%1$x %1$d) is inputed", c);
	}
}
```


More information about the Digitalmars-d-learn mailing list