3535
3636 // Javascript event.button 0 = left, 1 = middle, 2 = right
3737 test_t g_tests [] = {
38- { "Module.injectMouseEvent (10.0, 10.0, 'mousedown' , 0)" , { 1 , 10.0 , 10.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_PRESS , -1 } },
39- { "Module.injectMouseEvent (10.0, 20.0, 'mouseup' , 0)" , { 1 , 10.0 , 20.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_RELEASE , -1 } },
40- { "Module.injectMouseEvent (10.0, 30.0, 'mousedown' , 1)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_PRESS , -1 } },
41- { "Module.injectMouseEvent (10.0, 40.0, 'mouseup' , 1)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_RELEASE , -1 } },
42- { "Module.injectMouseEvent (10.0, 30.0, 'mousedown' , 2)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_PRESS , -1 } },
43- { "Module.injectMouseEvent (10.0, 40.0, 'mouseup' , 2)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_RELEASE , -1 } },
44- //{ "Module.injectMouseEvent( 10.0, 50.0, 'mousewheel', 0)", { 10.0, 50.0, -1, -1, -1 } },
45- //{ "Module.injectMouseEvent (10.0, 60.0, 'mousemove', 0)", { 10.0, 60.0, -1, -1, -1 } }
46-
47- { "Module.injectKeyEvent( 'keydown', 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_PRESS , -1 } },
48- { "Module.injectKeyEvent( 'keyup', 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_RELEASE , -1 } },
49- { "Module.injectKeyEvent( 'keydown', 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_PRESS , -1 } },
50- { "Module.injectKeyEvent( 'keyup', 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_RELEASE , -1 } },
51- { "Module.injectKeyEvent( 'keydown', 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_PRESS , -1 } },
52- { "Module.injectKeyEvent( 'keyup', 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_RELEASE , -1 } },
53- { "Module.injectKeyEvent( 'keydown', 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_PRESS , -1 } },
54- { "Module.injectKeyEvent( 'keyup', 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_RELEASE , -1 } },
55- { "Module.injectKeyEvent( 'keydown', 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_PRESS , -1 } },
56- { "Module.injectKeyEvent( 'keyup', 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_RELEASE , -1 } },
57- { "Module.injectKeyEvent( 'keydown', 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_PRESS , -1 } },
58- { "Module.injectKeyEvent( 'keyup', 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_RELEASE , -1 } },
59- { "Module.injectKeyEvent( 'keydown', 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_PRESS , -1 } },
60- { "Module.injectKeyEvent( 'keyup', 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_RELEASE , -1 } },
38+ { "simulateMouseDown (10.0, 10.0, 0)" , { 1 , 10.0 , 10.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_PRESS , -1 } },
39+ { "simulateMouseUp (10.0, 20.0, 0)" , { 1 , 10.0 , 20.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_RELEASE , -1 } },
40+ { "simulateMouseDown (10.0, 30.0, 1)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_PRESS , -1 } },
41+ { "simulateMouseUp (10.0, 40.0, 1)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_RELEASE , -1 } },
42+ { "simulateMouseDown (10.0, 30.0, 2)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_PRESS , -1 } },
43+ { "simulateMouseUp (10.0, 40.0, 2)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_RELEASE , -1 } },
44+ //{ "simulateMouseEvent('mousewheel', 10.0, 50.0)", { 10.0, 50.0, -1, -1, -1 } },
45+ //{ "simulateMouseMove (10.0, 60.0)", { 10.0, 60.0, -1, -1, -1 } }
46+
47+ { "simulateKeyEvent(document, 'keydown', 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_PRESS , -1 } },
48+ { "simulateKeyEvent(document, 'keyup', 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_RELEASE , -1 } },
49+ { "simulateKeyEvent(document, 'keydown', 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_PRESS , -1 } },
50+ { "simulateKeyEvent(document, 'keyup', 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_RELEASE , -1 } },
51+ { "simulateKeyEvent(document, 'keydown', 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_PRESS , -1 } },
52+ { "simulateKeyEvent(document, 'keyup', 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_RELEASE , -1 } },
53+ { "simulateKeyEvent(document, 'keydown', 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_PRESS , -1 } },
54+ { "simulateKeyEvent(document, 'keyup', 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_RELEASE , -1 } },
55+ { "simulateKeyEvent(document, 'keydown', 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_PRESS , -1 } },
56+ { "simulateKeyEvent(document, 'keyup', 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_RELEASE , -1 } },
57+ { "simulateKeyEvent(document, 'keydown', 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_PRESS , -1 } },
58+ { "simulateKeyEvent(document, 'keyup', 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_RELEASE , -1 } },
59+ { "simulateKeyEvent(document, 'keydown', 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_PRESS , -1 } },
60+ { "simulateKeyEvent(document, 'keyup', 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_RELEASE , -1 } },
6161
6262 #if USE_GLFW == 2
63- { "Module.injectKeyEvent( 'keydown', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_PRESS , -1 } },
64- { "Module.injectKeyEvent( 'keyup', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_RELEASE , -1 } },
63+ { "simulateKeyEvent(document, 'keydown', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_PRESS , -1 } },
64+ { "simulateKeyEvent(document, 'keyup', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_RELEASE , -1 } },
6565
66- { "Module.injectKeyEvent( 'keydown', 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
67- { "Module.injectKeyEvent( 'keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
68- { "Module.injectKeyEvent( 'keyup', 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
66+ { "simulateKeyEvent(document, 'keydown', 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
67+ { "simulateKeyEvent(document, 'keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
68+ { "simulateKeyEvent(document, 'keyup', 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
6969
70- { "Module.injectKeyEvent( 'keydown', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
71- { "Module.injectKeyEvent( 'keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
72- { "Module.injectKeyEvent( 'keyup', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
70+ { "simulateKeyEvent(document, 'keydown', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
71+ { "simulateKeyEvent(document, 'keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
72+ { "simulateKeyEvent(document, 'keyup', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
7373 #else
74- { "Module.injectKeyEvent( 'keydown', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_PRESS , -1 } },
75- { "Module.injectKeyEvent( 'keyup', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_RELEASE , -1 } },
74+ { "simulateKeyEvent(document, 'keydown', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_PRESS , -1 } },
75+ { "simulateKeyEvent(document, 'keyup', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_RELEASE , -1 } },
7676
77- { "Module.injectKeyEvent( 'keydown', 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 } },
78- { "Module.injectKeyEvent( 'keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
79- { "Module.injectKeyEvent( 'keyup', 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 } },
77+ { "simulateKeyEvent(document, 'keydown', 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 } },
78+ { "simulateKeyEvent(document, 'keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
79+ { "simulateKeyEvent(document, 'keyup', 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 } },
8080
81- { "Module.injectKeyEvent( 'keydown', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 , 'A' } },
82- { "Module.injectKeyEvent( 'keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
83- { "Module.injectKeyEvent( 'keyup', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 , 'A' } },
81+ { "simulateKeyEvent(document, 'keydown', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 , 'A' } },
82+ { "simulateKeyEvent(document, 'keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
83+ { "simulateKeyEvent(document, 'keyup', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 , 'A' } },
8484 #endif
8585 };
8686
182182 int result = 1 ;
183183 unsigned int success = (1 << (sizeof (g_tests ) / sizeof (test_t ))) - 1 ; // (2^count)-1;
184184
185- emscripten_run_script (MULTILINE (
186- Module .injectMouseEvent = function (x , y , event_ , button ) {
187- var canvas = Module ['canvas' ];
188- var event = new MouseEvent (event_ , {
189- 'view' : window ,
190- 'bubbles' : true,
191- 'cancelable' : true,
192- 'screenX' : canvas .offsetLeft + x ,
193- 'screenY' : canvas .offsetTop + y ,
194- 'clientX' : canvas .offsetLeft + x ,
195- 'clientY' : canvas .offsetTop + y ,
196- 'button' : button
197- });
198- canvas .dispatchEvent (event );
199-
200- //var event = document.createEvent("MouseEvents");
201- //var canvas = Module['canvas'];
202- //event.initMouseEvent(event_, true, true, window, 0, canvas.offsetLeft + x, canvas.offsetTop + y, canvas.offsetLeft + x, canvas.offsetTop + y, 0, 0, 0, 0, button, null);
203- //canvas.dispatchEvent(event);
204- };
205-
206- Module .injectKeyEvent = function (type , keyCode , options ) {
207- // KeyboardEvent constructor always returns 0 keyCode on Chrome, so use generic events
208- //var keyboardEvent = new KeyboardEvent(type, Object.assign({ keyCode: keyCode}, options));
209- var keyboardEvent = document .createEventObject ?
210- document .createEventObject () : document .createEvent ('Events' );
211- keyboardEvent .initEvent (type , true, true);
212- keyboardEvent .keyCode = keyCode ;
213- keyboardEvent = Object .assign (keyboardEvent , options );
214-
215- canvas .dispatchEvent (keyboardEvent );
216- };
217- ));
218-
219185 glfwInit ();
220186
221187 #if USE_GLFW == 2
222188 glfwOpenWindow (WIDTH , HEIGHT , 5 , 6 , 5 , 0 , 0 , 0 , GLFW_WINDOW ); // != GL_TRUE)
223-
189+
224190 glfwSetMousePosCallback (on_mouse_move );
225191 glfwSetCharCallback (on_char_callback );
226192 #else
297263
298264 return 0 ;
299265 }
300- #endif
266+ #endif
0 commit comments