Using Fable in an Elmish app, I'd like to listen to the keyboard directly and get each keystroke as a message.
The Elmish documentation has a page on Subscriptions, which shows how to convert JavaScript events to messages. In my case, the events are "keydown" events, and I found code in JavaScript to capture "keydown" events.
However, I'm having trouble putting the F# code together. My issue is that I don't know how to access the keyCode
from the event raised when a key is pressed. Here's the code I have so far:
let keyDown initial =
let sub dispatch =
document.addEventListener("keydown", fun e ->
dispatch (KeyDown e.keyCode)) // keyCode is not accessible here
Cmd.ofSub sub