Guest User

Untitled

a guest
Mar 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import GHCJS.DOM.Document (getBody)
  2. import GHCJS.DOM.EventM (on, preventDefault)
  3. import GHCJS.DOM.GlobalEventHandlers (keyDown)
  4. import Reflex.Dom hiding (preventDefault)
  5. import Web.KeyCode
  6.  
  7. main :: IO ()
  8. main = mainWidget $ do
  9. doc <- askDocument
  10. Just body <- getBody doc
  11. kp <- wrapDomEvent body (`on` keyDown) $ do
  12. preventDefault -- This 'preventDefault' is here to prevent
  13. -- the browser's default behavior when keys
  14. -- like <F1> or the arrow keys are pressed.
  15. -- If you want to preserve default behavior
  16. -- this can be removed, or you can apply it
  17. -- selectively, only to certain keypresses.
  18. i <- getKeyEvent
  19. return i
  20. lastKeyPressed <- holdDyn Nothing $
  21. Just . keyCodeLookup . fromEnum <$> kp
  22. display lastKeyPressed
Add Comment
Please, Sign In to add comment