How to getCh on MS Windows command line?

Ahn, Ki Yung kyagrd at
Mon Nov 10 00:16:09 EST 2008

What I mean by getCh is the non-buffered non-echoed version of getChar,
which Hugs used to provided as an extension but not any more.

Is there any way to have a non-buffered non-echoed single character
input function on MS Windows command line using only the libraries in
the MS Windows distribution packages of either GHC or Hugs?

The reason to why this is important for me is because I am translating
Graham Hutton's "Programming in Haskell" into Korean (soon to be
published), which illustrates interactive programming with the example
of a calculator that responds instantly for every keystroke of numbers
and arithmetic operations running on text mode.  It is very important to
consider the readers who only have access to MS Windows systems, because
Korean OS market share is completely skewed towards MS Windows for very
embarrassing reasons that I do not even want to mention.  And, isn't GHC
developed in MSR anyway?  :-)

I remember that this is an old problem for both of the two most widely
used Haskell implementation, Hugs and GHC.

In ghc 6.8 getChar had a bit strange behavior.  As far as I remember it
always worked as if it were NoBuffering.  Fortunately, in the recently
released ghc 6.10, this has been fixed.  We now actually have to set the
buffering mode to NoBuffering with hSetBufferring to get the
non-buffered behavior of getChar.  But, it still isn't working on MS

In Hugs, hSetBuffering neither works on Unix terminal nor on MS Windows
command line.  Surprisingly, it works in WinHugs.  However, I cannot use
WinHugs for my purpose because the interactive calculator example in the
book also uses beep characters and ANSI codes which do not work in WinHugs.

Thanks for any hacks or suggestions,

  Ahn, Ki Yung

More information about the Glasgow-haskell-users mailing list