= Getch/Getchar = ''Part of'' TutorialFundamentals == Description == Get a character from the keyboard. == Example == {{{ #!d import std.c.stdio; import std.stdio; void main() { char k; writefln("\nI'm going to ask you to press 10 keys (I promise it's painless).\n" "Certain keys don't count, but the whole alphabet is fair game.\n"); for(int i = 0; i < 10; i++) { version(Windows) { writef("Press key: %d\t", i); k = getch(); } version(linux) { writef("Press key (follow with return): %d\t", i); k = getchar(); } version(OSX) { // Unfortunately, merely using getchar() does not disable stdin and readline buffering. writef("Press key (follow with return): %d\t", i); k = getchar(); } writef("[%s]\t", k); /* print the character pressed */ writefln("[%d]\n", k); /* print ASCII code for key */ } writefln("\nThe End.\n"); } }}} == Source == Based on [http://jcc_7.tripod.com/d/tutor/simple/getch.html getch.html] by jcc7. Changed 2004-06-01: Added an untested Linux version based on a suggestion ([http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=2383 digitalmars.D/2383]). Changed 2009-03-01: Added a tested OS X version, based on dmd now available for OS X 10.5 (both D 1.0 and D 2.0 alpha).