www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Single char input in D

reply "Bob W" <nospam aol.com> writes:
Correct me if I am wrong, but there seems to be
no native support in D for getting a single char
from the keyboard.

While 'printf' has been elegantly replaced, nothing
as simple as a 'getch' or 'getche' equivalent seems
to exist in D.

The closest I could get to was to rely on Phobos'
std.cstream and using 'din.getch'. It is
currently not documented (unlike 'din.getc'),
but I regarded it as implied that it would work.

Unfortunately 'din.getche' has obviously the
same bug as its C counterpart in dmc - it
simply does not do what it should
(echoed 'getch').

The whole think makes me wondering if I have
overlooked something or if I am the last person
here using D console apps which actually expect
characters from the keyboard without EOLs
attached to them.

Remaining questions are:

- Can I rely on 'din.getch' being available in future,
even though it is not explicitly mentioned in the
Phobos docs?

- Will 'getche' eventually work properly one day?

- Is there any method available/planned in D for
reading extended keycodes from the keyboard?
Feb 28 2006
next sibling parent reply "Derek Parnell" <derek psych.ward> writes:
On Tue, 28 Feb 2006 23:14:53 +1100, Bob W <nospam aol.com> wrote:

 Correct me if I am wrong, but there seems to be
 no native support in D for getting a single char
 from the keyboard.
I used 'getch()' and that seemed to work okay. -- Derek Parnell Melbourne, Australia
Feb 28 2006
parent "Bob W" <nospam aol.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message 
news:op.s5om75qa6b8z09 ginger.vic.bigpond.net.au...

 I used 'getch()' and that seemed to work okay.
Yes, we both know that it works (as opposed to getche() ). But it is borrowed from good ol' C and I am wondering if an enthusiastic D (and C) newbie would find a solution just by digging through Phobos ....
Feb 28 2006
prev sibling parent reply Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Bob W wrote:
 Correct me if I am wrong, but there seems to be
 no native support in D for getting a single char
 from the keyboard.
 
 While 'printf' has been elegantly replaced, nothing
 as simple as a 'getch' or 'getche' equivalent seems
 to exist in D.
 
 The closest I could get to was to rely on Phobos'
 std.cstream and using 'din.getch'. It is
 currently not documented (unlike 'din.getc'),
 but I regarded it as implied that it would work.
 
 Unfortunately 'din.getche' has obviously the
 same bug as its C counterpart in dmc - it
 simply does not do what it should
 (echoed 'getch').
 
 The whole think makes me wondering if I have
 overlooked something or if I am the last person
 here using D console apps which actually expect
 characters from the keyboard without EOLs
 attached to them.
 
 Remaining questions are:
 
 - Can I rely on 'din.getch' being available in future,
 even though it is not explicitly mentioned in the
 Phobos docs?
 
 - Will 'getche' eventually work properly one day?
 
 - Is there any method available/planned in D for
 reading extended keycodes from the keyboard?
 
 
 
getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They are Borland extensions if I'm not mistaken. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
Mar 02 2006
next sibling parent Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
Bruno Medeiros wrote:
 getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They
 are Borland extensions if I'm not mistaken.
 
Nevertheless both getch() and getche() are extremely useful and deserve their places in D, regardless of whether or not they are part of any C standard. What I'd really like is a full Curses-type, platform-independent (well, *nix/Windows) module in the standard library, but I'm fairly sure that's not going to happen at least any time soon. Curses itself is just such a pain in far too many respects.
Mar 02 2006
prev sibling parent reply "Bob W" <nospam aol.com> writes:
"Bruno Medeiros" <daiphoenixNO SPAMlycos.com> wrote in message 
news:du74jc$1hrs$3 digitaldaemon.com...

 getch() and getche() are not ANSI/ISO C (thus not "good ol' C"). They are 
 Borland extensions if I'm not mistaken.
Tell me any major C compiler NOT featuring getch() or _getch(). It simply is a necessity having it as part of a C library. Therefore it is widely available and it does not matter at all whether it is standardized or not.
Mar 03 2006
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Bob W wrote:

 Tell me any major C compiler NOT featuring getch() or _getch().
 It simply is a necessity having it as part of a C library. Therefore
 it is widely available and it does not matter at all whether it is
 standardized or not.
Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h Of course, to use that you need to link to the libncurses.dylib too. --anders
Mar 03 2006
parent reply Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Anders F Björklund wrote:
 Bob W wrote:
 
 Tell me any major C compiler NOT featuring getch() or _getch().
 It simply is a necessity having it as part of a C library. Therefore
 it is widely available and it does not matter at all whether it is
 standardized or not.
Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h Of course, to use that you need to link to the libncurses.dylib too. --anders
That's the same for all gcc everywhere, right? -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
Mar 04 2006
parent "Bob W" <nospam aol.com> writes:
"Bruno Medeiros" <daiphoenixNO SPAMlycos.com> wrote in message 
news:dubpb0$tki$1 digitaldaemon.com...
 Anders F Björklund wrote:
 Mac OS X only has "getchar"... "getch" is in (the bundled) ncurses.h
 Of course, to use that you need to link to the libncurses.dylib too.

 --anders
That's the same for all gcc everywhere, right?
Not everywhere - gcc based djgpp offers getch() in conio.h
Mar 04 2006