martouta/html-key-events/1.0.0

HtmlKeyEvents

HTML Event listeners for on 'keyup' and on 'keydown'. For each one of them, it stops propagation.

onKeyDown : (( Int, Bool ) -> msg) -> Attribute msg

It will give you the ASCII code of the key being pressed. Plus, it will tell you if the shift key is pressed as well. You can read a complete simple example in the README.

type Msg
    = KeyDown ( Int, Bool )


view : Html Msg
view =
    textarea
        [ rows 10
        , cols 40
        , onKeyDown KeyDown
        ]
        []
    ]


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        KeyDown ( code, shift ) ->
            (model, Cmd.none)
onKeyUp : (Int -> msg) -> Attribute msg

It will give you the ASCII code of the key being released- You can read a complete simple example in the README.

type Msg
    KeyUp Int


view : Html Msg
view =
    textarea
        [ rows 10
        , cols 40
        , onKeyUp KeyUp
        ]
        []
    ]


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        KeyUp code ->
            (model, Cmd.none)