

Task

Obtain a valid   Y   or   N   response from the keyboard.

The keyboard should be flushed, so that any outstanding key-presses are removed, preventing any existing   Y   or   N   key-press from being evaluated.

The response should be obtained as soon as   Y   or   N   are pressed, and there should be no need to press an   enter   key.




import Char
import Graphics.Element exposing (Element, empty, show)
import Keyboard
 
 
view : Int -> Element
view keyCode =
  let
    char = 
      Char.fromCode keyCode
 
    showChar =
      toString >> ((++) "The last (y/n) key pressed was: ") >> show
  in
    case char of
      'n' ->
        showChar char
 
      'y' ->
        showChar char
 
      _ ->
        empty
 
 
main : Signal Element
main =
  Signal.map view Keyboard.presses