diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index def353a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: node_js - -node_js: - - "7.10" - -cache: - directories: - - elm-stuff/build-artifacts - - sysconfcpus - -before_install: - - | # epic build time improvement - see https://github.com/elm-lang/elm-compiler/issues/1473#issuecomment-245704142 - if [ ! -d sysconfcpus/bin ]; - then - git clone https://github.com/obmarg/libsysconfcpus.git; - cd libsysconfcpus; - ./configure --prefix=$TRAVIS_BUILD_DIR/sysconfcpus; - make && make install; - cd ..; - fi - -install: - - npm install -g elm - - mv $(npm config get prefix)/bin/elm-make $(npm config get prefix)/bin/elm-make-old - - printf "#\041/bin/bash\n\necho \"Running elm-make with sysconfcpus -n 2\"\n\n$TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 elm-make-old \"\$@\"" > $(npm config get prefix)/bin/elm-make - - chmod +x $(npm config get prefix)/bin/elm-make - - npm install -g elm-verify-examples - - npm install -g elm-test - - elm-package install -y - - pushd tests && elm-package install -y && popd - -script: - - elm-verify-examples && elm-test diff --git a/elm-package.json b/elm-package.json index b40e039..9a793a7 100644 --- a/elm-package.json +++ b/elm-package.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.2", "summary": "Convenience helpers for working with Keyboard with browser support", "repository": "https://github.com/Chadtech/keyboard-extra-browser.git", "license": "BSD3", diff --git a/example/Decoder.elm b/example/Decoder.elm deleted file mode 100644 index adf35af..0000000 --- a/example/Decoder.elm +++ /dev/null @@ -1,45 +0,0 @@ -module Main exposing (..) - -import Html exposing (..) -import Html.Events exposing (on) -import Keyboard.Extra as Keyboard -import Json.Decode as Json -import Style - - -main : Program Never Model Msg -main = - Html.beginnerProgram - { model = init - , update = update - , view = view - } - - -type alias Model = - Maybe Keyboard.Key - - -init : Model -init = - Nothing - - -type Msg - = KeyPress Keyboard.Key - - -update : Msg -> Model -> Model -update msg model = - case msg of - KeyPress char -> - Just char - - -view : Model -> Html Msg -view model = - div [ Style.container ] - [ p [] [ text "Enter text below:" ] - , textarea [ on "keydown" <| Json.map KeyPress Keyboard.targetKey ] [] - , p [] [ text <| toString model ] - ] diff --git a/example/ForceRelease.elm b/example/ForceRelease.elm deleted file mode 100644 index 3758220..0000000 --- a/example/ForceRelease.elm +++ /dev/null @@ -1,72 +0,0 @@ -module Main exposing (..) - -import Html exposing (Html, p, ul, li, text, div, button) -import Html.Events exposing (onClick) -import Keyboard.Extra as KeyEx exposing (Key) -import Style - - -type Msg - = KeyboardMsg KeyEx.Msg - | ForceRelease - - -{-| We don't need any other info in the model, since we can get everything we -need using the helpers right in the `view`! - -This way we always have a single source of truth, and we don't need to remember -to do anything special in the update. --} -type alias Model = - { pressedKeys : List Key - } - - -init : ( Model, Cmd Msg ) -init = - ( Model [] - , Cmd.none - ) - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - KeyboardMsg keyMsg -> - ( { model - | pressedKeys = KeyEx.update keyMsg model.pressedKeys - } - , Cmd.none - ) - - ForceRelease -> - ( { model - | pressedKeys = List.filter ((/=) KeyEx.CharA) model.pressedKeys - } - , Cmd.none - ) - - -view : Model -> Html Msg -view model = - div [ Style.container ] - [ p [] [ button [ onClick ForceRelease ] [ text "Force release of CharA" ] ] - , p [] [ text "Currently pressed down:" ] - , ul [] - (List.map (\key -> li [] [ text (toString key) ]) model.pressedKeys) - ] - - -subscriptions : Model -> Sub Msg -subscriptions model = - Sub.map KeyboardMsg KeyEx.subscriptions - - -main : Program Never Model Msg -main = - Html.program - { init = init - , update = update - , view = view - , subscriptions = subscriptions - } diff --git a/example/Main.elm b/example/Main.elm deleted file mode 100644 index 463f29d..0000000 --- a/example/Main.elm +++ /dev/null @@ -1,75 +0,0 @@ -module Main exposing (..) - -import Html exposing (Html, div, p, ul, li, text) -import Keyboard.Extra exposing (Key(..)) -import Style - - -type Msg - = KeyboardMsg Keyboard.Extra.Msg - - -{-| We don't need any other info in the model, since we can get everything we -need using the helpers right in the `view`! - -This way we always have a single source of truth, and we don't need to remember -to do anything special in the update. --} -type alias Model = - { pressedKeys : List Key - } - - -init : ( Model, Cmd Msg ) -init = - ( { pressedKeys = [] } - , Cmd.none - ) - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - KeyboardMsg keyMsg -> - ( { model - | pressedKeys = Keyboard.Extra.update keyMsg model.pressedKeys - } - , Cmd.none - ) - - -view : Model -> Html msg -view model = - let - shiftPressed = - List.member Shift model.pressedKeys - - arrows = - Keyboard.Extra.arrows model.pressedKeys - - wasd = - Keyboard.Extra.wasd model.pressedKeys - in - div [ Style.container ] - [ text ("Shift: " ++ toString shiftPressed) - , p [] [ text ("Arrows: " ++ toString arrows) ] - , p [] [ text ("WASD: " ++ toString wasd) ] - , p [] [ text "Currently pressed down:" ] - , ul [] - (List.map (\key -> li [] [ text (toString key) ]) model.pressedKeys) - ] - - -subscriptions : Model -> Sub Msg -subscriptions model = - Sub.map KeyboardMsg Keyboard.Extra.subscriptions - - -main : Program Never Model Msg -main = - Html.program - { init = init - , update = update - , view = view - , subscriptions = subscriptions - } diff --git a/example/PlainSubscriptions.elm b/example/PlainSubscriptions.elm deleted file mode 100644 index 3e7a7dd..0000000 --- a/example/PlainSubscriptions.elm +++ /dev/null @@ -1,65 +0,0 @@ -module PlainSubscriptions exposing (..) - -import Html exposing (Html, div, p, ul, li, text) -import Keyboard.Extra exposing (Key) -import Style - - -{- Subscribing to keyboard events without the whole model-update -thing. -} - - -subscriptions : Model -> Sub Msg -subscriptions model = - Sub.batch - [ Keyboard.Extra.downs KeyDown - , Keyboard.Extra.ups KeyUp - ] - - -main : Program Never Model Msg -main = - Html.program - { init = init - , update = update - , view = view - , subscriptions = subscriptions - } - - -type Msg - = KeyDown Key - | KeyUp Key - - -type alias Model = - { events : List String - } - - -init : ( Model, Cmd Msg ) -init = - ( Model [] - , Cmd.none - ) - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - ( { model | events = (toString msg) :: model.events } - , Cmd.none - ) - - -view : Model -> Html msg -view model = - div [ Style.container ] - [ p [] [ text "Try pressing, releasing and long-pressing keys." ] - , keysView model - ] - - -keysView : Model -> Html msg -keysView model = - model.events - |> List.map (\event -> li [] [ text event ]) - |> ul [] diff --git a/example/Style.elm b/example/Style.elm deleted file mode 100644 index 2ec16ad..0000000 --- a/example/Style.elm +++ /dev/null @@ -1,21 +0,0 @@ -module Style exposing (..) - -import Html -import Html.Attributes exposing (style) - - -container : Html.Attribute msg -container = - style - [ ( "background-color", "rebeccapurple" ) - , ( "color", "white" ) - , ( "font-family", "sans-serif" ) - , ( "width", "100vw" ) - , ( "height", "100vh" ) - , ( "display", "flex" ) - , ( "align-items", "center" ) - , ( "justify-content", "flex-start" ) - , ( "box-sizing", "border-box" ) - , ( "padding", "4em 2em" ) - , ( "flex-direction", "column" ) - ] diff --git a/example/TrackingKeyChanges.elm b/example/TrackingKeyChanges.elm deleted file mode 100644 index b9a362f..0000000 --- a/example/TrackingKeyChanges.elm +++ /dev/null @@ -1,76 +0,0 @@ -module TrackingKeyChanges exposing (..) - -import Html exposing (Html, div, p, ul, li, text) -import Keyboard.Extra exposing (Key(..)) -import Style - - -main : Program Never Model Msg -main = - Html.program - { init = init - , update = update - , view = view - , subscriptions = subscriptions - } - - -type Msg - = KeyboardMsg Keyboard.Extra.Msg - - -type alias Model = - { pressedKeys : List Key - , keyChanges : List Keyboard.Extra.KeyChange - } - - -init : ( Model, Cmd Msg ) -init = - ( Model [] [] - , Cmd.none - ) - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - KeyboardMsg keyMsg -> - let - ( pressedKeys, maybeKeyChange ) = - Keyboard.Extra.updateWithKeyChange keyMsg model.pressedKeys - - keyChanges = - case maybeKeyChange of - Just keyChange -> - keyChange :: model.keyChanges - - Nothing -> - model.keyChanges - in - ( { model - | pressedKeys = pressedKeys - , keyChanges = keyChanges - } - , Cmd.none - ) - - -view : Model -> Html msg -view model = - div [ Style.container ] - [ p [] [ text "Try pressing, releasing and long-pressing keys." ] - , keysView model - ] - - -keysView : Model -> Html msg -keysView model = - model.keyChanges - |> List.map (\change -> li [] [ text (toString change) ]) - |> ul [] - - -subscriptions : Model -> Sub Msg -subscriptions model = - Sub.map KeyboardMsg Keyboard.Extra.subscriptions diff --git a/example/VisualArrows.elm b/example/VisualArrows.elm deleted file mode 100644 index 84dc00e..0000000 --- a/example/VisualArrows.elm +++ /dev/null @@ -1,131 +0,0 @@ -module VisualArrows exposing (..) - -import Html exposing (Html, p, div, text) -import Html.Attributes exposing (style) -import Keyboard.Extra exposing (Key, Direction(..)) -import Style - - -main : Program Never Model Msg -main = - Html.program - { init = init - , update = update - , view = view - , subscriptions = subscriptions - } - - -type Msg - = KeyboardMsg Keyboard.Extra.Msg - - -type alias Model = - { pressedKeys : List Key - } - - -init : ( Model, Cmd Msg ) -init = - ( Model [] - , Cmd.none - ) - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - KeyboardMsg keyMsg -> - ( { model - | pressedKeys = Keyboard.Extra.update keyMsg model.pressedKeys - } - , Cmd.none - ) - - -view : Model -> Html msg -view model = - let - arrows = - Keyboard.Extra.arrowsDirection model.pressedKeys - - wasd = - Keyboard.Extra.wasdDirection model.pressedKeys - in - div [ Style.container ] - [ div [] - [ p [] [ text ("Arrows: " ++ toString arrows) ] - , directionView arrows - ] - , div - [] - [ p [] [ text ("WASD: " ++ toString wasd) ] - , directionView wasd - ] - ] - - -directionView : Direction -> Html msg -directionView direction = - let - angle = - directionToAngle direction - |> toString - - char = - case direction of - NoDirection -> - "🞄" - - _ -> - "↑" - in - p - [ style - [ ( "transform", "rotate(" ++ angle ++ "rad)" ) - , ( "width", "1em" ) - , ( "height", "1em" ) - , ( "line-height", "1" ) - , ( "text-align", "center" ) - , ( "margin", "auto" ) - , ( "font-size", "10em" ) - ] - ] - [ text char - ] - - -directionToAngle : Direction -> Float -directionToAngle direction = - case direction of - North -> - 0 - - NorthEast -> - pi * 0.25 - - East -> - pi * 0.5 - - SouthEast -> - pi * 0.75 - - South -> - pi * 1 - - SouthWest -> - pi * 1.25 - - West -> - pi * 1.5 - - NorthWest -> - pi * 1.75 - - NoDirection -> - 0 - - -subscriptions : Model -> Sub Msg -subscriptions model = - Sub.map KeyboardMsg Keyboard.Extra.subscriptions diff --git a/example/elm-package.json b/example/elm-package.json deleted file mode 100644 index 71e8c6f..0000000 --- a/example/elm-package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "1.0.0", - "summary": "Examples for keyboard-extra", - "repository": "https://github.com/ohanhi/keyboard-extra.git", - "license": "BSD3", - "source-directories": [ - ".", - "../src" - ], - "exposed-modules": [], - "dependencies": { - "elm-lang/core": "5.0.0 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0", - "elm-lang/keyboard": "1.0.1 <= v < 2.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/src/Keyboard/Extra/Browser.elm b/src/Keyboard/Extra/Browser.elm index 605007f..225e7e4 100644 --- a/src/Keyboard/Extra/Browser.elm +++ b/src/Keyboard/Extra/Browser.elm @@ -355,6 +355,13 @@ fromCode browser = fromCodeBasic notFireFoxCodeDict +fromCodeBasic : Dict KeyCode Key -> KeyCode -> Key +fromCodeBasic dict keyCode = + dict + |> Dict.get keyCode + |> Maybe.withDefault Other + + {-| Convert a `Key` into a key code. toCode Chrome Enter --> 13 @@ -363,7 +370,7 @@ fromCode browser = -} toCode : Browser -> Key -> KeyCode -toCode browser key = +toCode browser = case browser of FireFox -> toCodeBasic fireFoxCodeBook @@ -566,7 +573,7 @@ fireFoxCodeDict = notFireFoxCodeDict : Dict KeyCode Key notFireFoxCodeDict = - Dict.fromList notFixFoxCodeBook + Dict.fromList notFireFoxCodeBook notFireFoxCodeBook : List ( Int, Key ) @@ -574,7 +581,7 @@ notFireFoxCodeBook = [ ( 173, VolumeMute ) , ( 174, VolumeDown ) , ( 175, VolumeUp ) - , ( 186, SemiColon ) + , ( 186, Semicolon ) , ( 187, Equals ) , ( 189, HyphenMinus ) ] @@ -586,7 +593,7 @@ fireFoxCodeBook = [ ( 181, VolumeMute ) , ( 182, VolumeDown ) , ( 183, VolumeUp ) - , ( 59, SemiColon ) + , ( 59, Semicolon ) , ( 61, Equals ) , ( 173, HyphenMinus ) ] diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index cd0928a..0000000 --- a/tests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/elm-stuff/ -/Doc/ diff --git a/tests/elm-package.json b/tests/elm-package.json deleted file mode 100644 index 873389f..0000000 --- a/tests/elm-package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": "1.0.0", - "summary": "Sample Elm Test", - "repository": "https://github.com/user/project.git", - "license": "BSD-3-Clause", - "source-directories": [ - ".", - "../src" - ], - "exposed-modules": [], - "dependencies": { - "elm-community/elm-test": "4.0.0 <= v < 5.0.0", - "elm-community/json-extra": "2.0.0 <= v < 3.0.0", - "elm-lang/core": "5.0.0 <= v < 6.0.0", - "elm-lang/html": "2.0.0 <= v < 3.0.0", - "elm-lang/keyboard": "1.0.1 <= v < 2.0.0", - "mgold/elm-random-pcg": "4.0.2 <= v < 5.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/tests/elm-verify-examples.json b/tests/elm-verify-examples.json deleted file mode 100644 index 523086a..0000000 --- a/tests/elm-verify-examples.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "root": "../src", - "tests": [ - "Keyboard.Extra" - ] -}