[Haskell-cafe] Re: Read a single char

Brian Smith brianlsmith at gmail.com
Mon Oct 23 23:28:15 EDT 2006


On 10/23/06, Neil Mitchell <ndmitchell at gmail.com> wrote:
>
> Hi
>
> >    getChar doesn't return until I press Enter. I need something that
> > returns immediately after I press any key.
>
> It's a problem with buffering:
>
> hSetBuffering stdin NoBuffering


This usually doesn't work on Windows:

GHC 6.4.2 and 6.6: requires <enter>
Hugs (console) Sept. 2006: requires <enter>
WinHugs (GUI) Sept. 2006: works as expected

But it seems to work on Linux:
GHC 6.4.1 on Ubuntu 6.06: works as expected
GHC 6.6 on Ubuntu 6.06: works as expected

I am really interested in hearing of a solution that works on all platforms.

> import IO
> main = do
>    hSetBuffering stdin NoBuffering
>    hGetChar stdin

Regards,
Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061023/d2c7158e/attachment.htm


More information about the Haskell-Cafe mailing list