I am using the HTML5 C Api in the Emscripten project to listen to DOM events ( A big thanks to Jukka ! ) :
https://github.com/kripken/emscripten/commit/96895e6dae8cf1314f8b4ce3fbab4e7c70ecaf4a I subscribed to keyboard and mouse events in the following way : * #include <emscripten.h>* * #include <emscripten/html5.h>* * #include <stdio.h>* * EM_BOOL key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData)* * {* * printf("You pressed key %lu\n", e->which);* * return 1;* * }* * EM_BOOL click_callback(int eventType, const EmscriptenMouseEvent *e, void *userData)* * {* * printf("You just clicked\n");* * return 1;* * }* * int main()* * {* * emscripten_set_keypress_callback(0, 0, 1, key_callback);* * emscripten_set_click_callback( "#document" , 0, 1, click_callback);* * EM_ASM(Module['noExitRuntime'] = true);* * return 0;* * }* I included the a.out.js in my HTML and the callbacks for keyboard gets called without any issues. But I see some issues when a mouse event is triggered. Sample Log ( 1st line for keyboard input and 2nd for mouse ) You pressed key 116 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined And this is where the exception happens in code : (a.out.js) *fillMouseEventData:function (eventStruct, e) {* * var rect = Module['canvas'].getBoundingClientRect();* * HEAPF64[((eventStruct)>>3)]=JSEvents.tick();* The Module['canvas'] object is not defined. I think this Module['canvas'] is applicable only when we are listening to events on a canvas generated from C/C++. But in my case, I want to listen to the entire document. I do specify that in the C API ( in the above C code ): * emscripten_set_click_callback("#document", 0, 1, click_callback);* Also, it is being set properly when the event is regitered in JS glue function and that's why it work as expected for Keyboard input: (a.out.js) *var eventHandler = {* * target: JSEvents.findEventTarget(target),* * allowsDeferredCalls: JSEvents.isInternetExplorer() ? false : true, // MSIE doesn't allow fullscreen and pointerlock requests from key handlers, others do.* * eventTypeString: eventTypeString,* * callbackfunc: callbackfunc,* * handlerFunc: handlerFunc,* * useCapture: useCapture* * };* It is just that in the case of Mouse events , there is an access to a non-existent Module['canvas'] object in my context. 3 questions : Is this a bug ? How do I get around this ? Am I missing out something here ? -Nagappan -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
