Skip to content

Instantly share code, notes, and snippets.

@alogic0
Forked from ali-abrar/globalKeypress.hs
Created September 27, 2016 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alogic0/ea93643d574077192a4375288d913421 to your computer and use it in GitHub Desktop.
Save alogic0/ea93643d574077192a4375288d913421 to your computer and use it in GitHub Desktop.
Global keypress events
-- source https://gist.github.com/ali-abrar/6cdf28d6fb9c3dbe25fb
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment