Skip to content

Instantly share code, notes, and snippets.

@plaxdan
Created June 7, 2016 16:24
Show Gist options
  • Save plaxdan/6a820d1f5e4a5cb55f17a027e6e10e59 to your computer and use it in GitHub Desktop.
Save plaxdan/6a820d1f5e4a5cb55f17a027e6e10e59 to your computer and use it in GitHub Desktop.
Subscribe to key presses
module Main exposing (..)
import Html exposing (Html, div, text)
import Html.App as App
import Keyboard exposing (KeyCode, presses)
type Msg
= KeyPressed KeyCode
type alias Model =
Int
init : ( Model, Cmd Msg )
init =
( -1, Cmd.none )
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
KeyPressed key ->
key ! []
view : Model -> Html Msg
view model =
div []
[ text ("You pressed key code " ++ (toString model))
]
subscriptions : Model -> Sub Msg
subscriptions model =
Keyboard.presses KeyPressed
main : Program Never
main =
App.program
{ init = init
, update = update
, view = view
, subscriptions = subscriptions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment