How to simulate Window's "Press any key to continue..."

Ali Çehreli acehreli at yahoo.com
Fri Nov 22 09:25:37 UTC 2019


On 11/21/19 9:10 PM, Mike Parker wrote:> On Friday, 22 November 2019 at 
04:45:21 UTC, Mike Parker wrote:

 > You need to call readf with a character
 > format string (%c):
 >
 > import std.stdio;
 > void main()
 > {
 >      writeln("Press any key to continue...");
 >
 >      char c;
 >      readf("%c", &c);
 >      writeln("Thanks!");
 > }

Unfortunately, that won't work either as it requires stdin to be 
unbuffered, which is not the case in most terminals.

The main issue here is that a D program cannot know that stdin is bound 
to a keyword. One needs to use a terminal module like the suggested 
curses or Adam's terminal.d:

   https://github.com/adamdruppe/arsd/blob/master/terminal.d

If it's too much unnecessary complication, then "Press Enter to 
continue..." is perfectly fine to me. ;) (But of course you can't move 
the cursor with that. :/)

Ali



More information about the Digitalmars-d-learn mailing list