This WindowKeys Elm module lets you encode and decode messages to pass to javascript, where the actual websocket sending and receiving will take place. See the README for more.
Only one WindowKeyCmd for now, SetWindowKeys. Use an empty list to stop all key messages.
json to Key struct
Key struct to json
make a subscription function with receive and a port, like so:
port receiveKeyMsg : (JD.Value -> msg) -> Sub msg
keyreceive =
receiveKeyMsg <| WindowKey.receive WsMsgWhere WkMsg is defined in your app like this:
type Msg
= WkMsg (Result JD.Error WindowKey.WindowKeyMsg)
| <other message types>then in your application subscriptions:
subscriptions =
\_ -> keyreceiveuse send to make a convenience function, like so:
port sendKeyCommand : JE.Value -> Cmd msg
wksend =
WindowKey.send sendKeyCommandthen you can call (makes a Cmd):
wksend <|
SetWindowKeys
[ { key = "s"
, ctrl = True
, alt = False
, shift = False
, preventDefault = True }
, { key = "Enter"
, ctrl = False
, alt = False
, shift = False
, preventDefault = False }
]
Key struct - both outgoing "SetWindowKeys" and incoming keypress messages.