Created
August 3, 2014 03:01
-
-
Save anonymous/25dd96829f15d989225a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data GUIEvent = KeyDownEvent { key_down__ctrl :: !Bool | |
, key_down__shift :: !Bool | |
, key_down__code :: !Int } | |
| MouseEvent { mouse__x :: !Int | |
, mouse__y ::!Int } | |
deriving (Show) | |
instance FromJSON GUIEvent where | |
parseJSON (Data.Aeson.Object v) = KeyDownEvent <$> | |
v .: (pack "ctrlKey") <*> | |
v .: (pack "shiftKey") <*> | |
v .: (pack "keyCode") | |
parseJSON _ = mzero | |
============= | |
function js_set_keydown_ (elem, cb) { | |
// console.log(elem); | |
elem.addEventListener( | |
"keydown", | |
function (evt) { | |
cb({ "tag" : "KeyDownEvent", | |
"ctrlKey" : evt.ctrlKey, | |
"shiftKey" : evt.shiftKey, | |
"keyCode" : evt.keyCode }); | |
}, false); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment