Skip to content

Instantly share code, notes, and snippets.

@ali-abrar
Created March 27, 2016 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ali-abrar/6cdf28d6fb9c3dbe25fb to your computer and use it in GitHub Desktop.
Save ali-abrar/6cdf28d6fb9c3dbe25fb to your computer and use it in GitHub Desktop.
Global keypress events
import Control.Monad.IO.Class
import GHCJS.DOM (webViewGetDomDocument)
import GHCJS.DOM.Document (getBody)
import GHCJS.DOM.Element (keyDown)
import GHCJS.DOM.EventM (on, preventDefault)
import Reflex.Dom
main :: IO ()
main = mainWidget $ do
wv <- askWebView
Just doc <- liftIO $ webViewGetDomDocument wv
Just body <- liftIO $ getBody doc
kp <- wrapDomEvent body (`on` keyDown) $ do
i <- getKeyEvent
preventDefault
return i
display =<< holdDyn Nothing (fmap Just kp)
@ali-abrar
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment