[Haskell-cafe] Character I/O

Edward Kmett ekmett at gmail.com
Tue Mar 31 15:44:18 EDT 2009

You want to use:

> main = do hSetBuffering stdin NoBuffering; c <- getChar
Your problem is that by default, POSIX environments use line buffering on
stdin queuing up until it sees a carriage return before sending it to the
process. Which is in this case, your code.

-Edward Kmett

On Tue, Mar 31, 2009 at 3:38 PM, Andrew Coppin
<andrewcoppin at btinternet.com>wrote:

> I ran the following program:
> >module Main where
> >
> >main = do
> >  putStrLn "Key"
> >  c <- getChar
> >  print c
> >  main
> Unfortunately, it doesn't do what I was hoping. Specifically, it only
> returns any data when I hit [return]. It also seems to be giving me a
> command history somehow. Special keys (e.g., arrow keys, backspace, escape)
> don't get through to the application.
> I'm trying to write a program that uses individual keys as commands. What's
> the correct way to get this to work?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090331/ca048583/attachment.htm

More information about the Haskell-Cafe mailing list