Skip to content

Instantly share code, notes, and snippets.

@ronanyeah
Created March 3, 2018 18:42
Show Gist options
  • Save ronanyeah/b3a5bf2a62e48b7d745867567e0c4353 to your computer and use it in GitHub Desktop.
Save ronanyeah/b3a5bf2a62e48b7d745867567e0c4353 to your computer and use it in GitHub Desktop.
Escape Listener
onEsc : msg -> Decoder msg
onEsc msg =
Decode.map2
(\keyCode key ->
keyCode == 27 || key == "Escape"
)
keyCode
(Decode.field "key" Decode.string)
|> Decode.andThen
(\match ->
if match then
Decode.succeed msg
else
Decode.fail ""
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment