Created
June 7, 2016 16:24
-
-
Save plaxdan/6a820d1f5e4a5cb55f17a027e6e10e59 to your computer and use it in GitHub Desktop.
Subscribe to key presses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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