Forked from anonymous/gist:25dd96829f15d989225a
Last active
August 29, 2015 14:04
Revisions
-
MichaelXavier revised this gist
Aug 3, 2014 . 1 changed file with 12 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,18 @@ data GUIEvent = KeyDownEvent { key_down__ctrl :: !Bool | MouseEvent { mouse__x :: !Int , mouse__y ::!Int } deriving (Show) instance FromJSON GUIEvent where parseJSON = withObject "GUIObject" parseGUIEvent parseGUIEvent v = parseKeyDownEvent v <|> parseMouseEvent parseKeyDownEvent = do tag <- v .: "tag" guard (tag == String "KeyDownEvent") KeyDownEvent <$> v .: "ctrlKey" <*> v .: "shiftKey" <*> v .: "keyCode" parseMouseEvent = do tag <- v .: "tag" guard (tag == String "MouseEvent") MouseEvent <$> v .: "x" <*> v .: "y" -
MichaelXavier revised this gist
Aug 3, 2014 . 1 changed file with 10 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,17 @@ {-# LANGUAGE OverloadedStrings #-} 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 = withObject "GUIObject" parseGUIEvent parseGUIEvent v = parseKeyDownEvent v <|> parseMouseEvent parseKeyDownEvent = KeyDownEvent <$> v .: "ctrlKey" <*> v .: "shiftKey" <*> v .: "keyCode" parseMouseEvent = MouseEvent <$> v .: "x" <*> v .: "y" -
There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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); }