Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import GHCJS.DOM.Document (getBody)
- import GHCJS.DOM.EventM (on, preventDefault)
- import GHCJS.DOM.GlobalEventHandlers (keyDown)
- import Reflex.Dom hiding (preventDefault)
- import Web.KeyCode
- main :: IO ()
- main = mainWidget $ do
- doc <- askDocument
- Just body <- getBody doc
- kp <- wrapDomEvent body (`on` keyDown) $ do
- preventDefault -- This 'preventDefault' is here to prevent
- -- the browser's default behavior when keys
- -- like <F1> or the arrow keys are pressed.
- -- If you want to preserve default behavior
- -- this can be removed, or you can apply it
- -- selectively, only to certain keypresses.
- i <- getKeyEvent
- return i
- lastKeyPressed <- holdDyn Nothing $
- Just . keyCodeLookup . fromEnum <$> kp
- display lastKeyPressed
Add Comment
Please, Sign In to add comment