martouta / html-key-events / HtmlKeyEvents

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

onKeyDown : (( Basics.Int, Basics.Bool ) -> msg) -> Html.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 : (Basics.Int -> msg) -> Html.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)