@@ -34,51 +34,51 @@ typedef struct {
3434
3535// Javascript event.button 0 = left, 1 = middle, 2 = right
3636test_t g_tests [] = {
37- { "Module.injectMouseEvent (10.0, 10.0, 'mousedown' , 0)" , { 1 , 10.0 , 10.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_PRESS , -1 } },
38- { "Module.injectMouseEvent (10.0, 20.0, 'mouseup' , 0)" , { 1 , 10.0 , 20.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_RELEASE , -1 } },
39- { "Module.injectMouseEvent (10.0, 30.0, 'mousedown' , 1)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_PRESS , -1 } },
40- { "Module.injectMouseEvent (10.0, 40.0, 'mouseup' , 1)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_RELEASE , -1 } },
41- { "Module.injectMouseEvent (10.0, 30.0, 'mousedown' , 2)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_PRESS , -1 } },
42- { "Module.injectMouseEvent (10.0, 40.0, 'mouseup' , 2)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_RELEASE , -1 } },
37+ { "simulateMouseDown (10.0, 10.0, 0)" , { 1 , 10.0 , 10.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_PRESS , -1 } },
38+ { "simulateMouseUp (10.0, 20.0, 0)" , { 1 , 10.0 , 20.0 , GLFW_MOUSE_BUTTON_LEFT , GLFW_RELEASE , -1 } },
39+ { "simulateMouseDown (10.0, 30.0, 1)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_PRESS , -1 } },
40+ { "simulateMouseUp (10.0, 40.0, 1)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_MIDDLE , GLFW_RELEASE , -1 } },
41+ { "simulateMouseDown (10.0, 30.0, 2)" , { 1 , 10.0 , 30.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_PRESS , -1 } },
42+ { "simulateMouseUp (10.0, 40.0, 2)" , { 1 , 10.0 , 40.0 , GLFW_MOUSE_BUTTON_RIGHT , GLFW_RELEASE , -1 } },
4343 //{ "Module.injectMouseEvent(10.0, 50.0, 'mousewheel', 0)", { 10.0, 50.0, -1, -1, -1 } },
4444 //{ "Module.injectMouseEvent(10.0, 60.0, 'mousemove', 0)", { 10.0, 60.0, -1, -1, -1 } }
4545
46- { "Module.injectKeyEvent('keydown', 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_PRESS , -1 } },
47- { "Module.injectKeyEvent('keyup', 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_RELEASE , -1 } },
48- { "Module.injectKeyEvent('keydown', 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_PRESS , -1 } },
49- { "Module.injectKeyEvent('keyup', 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_RELEASE , -1 } },
50- { "Module.injectKeyEvent('keydown', 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_PRESS , -1 } },
51- { "Module.injectKeyEvent('keyup', 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_RELEASE , -1 } },
52- { "Module.injectKeyEvent('keydown', 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_PRESS , -1 } },
53- { "Module.injectKeyEvent('keyup', 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_RELEASE , -1 } },
54- { "Module.injectKeyEvent('keydown', 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_PRESS , -1 } },
55- { "Module.injectKeyEvent('keyup', 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_RELEASE , -1 } },
56- { "Module.injectKeyEvent('keydown', 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_PRESS , -1 } },
57- { "Module.injectKeyEvent('keyup', 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_RELEASE , -1 } },
58- { "Module.injectKeyEvent('keydown', 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_PRESS , -1 } },
59- { "Module.injectKeyEvent('keyup', 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_RELEASE , -1 } },
46+ { "simulateKeyDown( 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_PRESS , -1 } },
47+ { "simulateKeyUp ( 8)" , { 0 , 0.0 , 0.0 , GLFW_KEY_BACKSPACE , GLFW_RELEASE , -1 } },
48+ { "simulateKeyDown( 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_PRESS , -1 } },
49+ { "simulateKeyUp ( 9)" , { 0 , 0.0 , 0.0 , GLFW_KEY_TAB , GLFW_RELEASE , -1 } },
50+ { "simulateKeyDown( 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_PRESS , -1 } },
51+ { "simulateKeyUp ( 112)" , { 0 , 0.0 , 0.0 , GLFW_KEY_F1 , GLFW_RELEASE , -1 } },
52+ { "simulateKeyDown( 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_PRESS , -1 } },
53+ { "simulateKeyUp ( 37)" , { 0 , 0.0 , 0.0 , GLFW_KEY_LEFT , GLFW_RELEASE , -1 } },
54+ { "simulateKeyDown( 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_PRESS , -1 } },
55+ { "simulateKeyUp ( 39)" , { 0 , 0.0 , 0.0 , GLFW_KEY_RIGHT , GLFW_RELEASE , -1 } },
56+ { "simulateKeyDown( 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_PRESS , -1 } },
57+ { "simulateKeyUp ( 38)" , { 0 , 0.0 , 0.0 , GLFW_KEY_UP , GLFW_RELEASE , -1 } },
58+ { "simulateKeyDown( 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_PRESS , -1 } },
59+ { "simulateKeyUp ( 40)" , { 0 , 0.0 , 0.0 , GLFW_KEY_DOWN , GLFW_RELEASE , -1 } },
6060 #if USE_GLFW == 2
61- { "Module.injectKeyEvent('keydown', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_PRESS , -1 } },
62- { "Module.injectKeyEvent('keyup', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_RELEASE , -1 } },
61+ { "simulateKeyDown( 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_PRESS , -1 } },
62+ { "simulateKeyUp( 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESC , GLFW_RELEASE , -1 } },
6363
64- { "Module.injectKeyEvent('keydown', 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
65- { "Module.injectKeyEvent ('keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
66- { "Module.injectKeyEvent('keyup', 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
64+ { "simulateKeyDown( 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
65+ { "simulateKeyEvent ('keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
66+ { "simulateKeyUp( 65)" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
6767
68- { "Module.injectKeyEvent('keydown', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
69- { "Module.injectKeyEvent ('keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
70- { "Module.injectKeyEvent('keyup', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
68+ { "simulateKeyDown( 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_PRESS , -1 , 'A' } },
69+ { "simulateKeyEvent ('keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
70+ { "simulateKeyUp( 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , 'A' , GLFW_RELEASE , -1 , 'A' } },
7171 #else
72- { "Module.injectKeyEvent('keydown', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_PRESS , -1 } },
73- { "Module.injectKeyEvent('keyup', 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_RELEASE , -1 } },
72+ { "simulateKeyDown( 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_PRESS , -1 } },
73+ { "simulateKeyUp( 27)" , { 0 , 0.0 , 0.0 , GLFW_KEY_ESCAPE , GLFW_RELEASE , -1 } },
7474
75- { "Module.injectKeyEvent('keydown', 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 } },
76- { "Module.injectKeyEvent ('keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
77- { "Module.injectKeyEvent('keyup', 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 } },
75+ { "simulateKeyDown( 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 } },
76+ { "simulateKeyEvent ('keypress', 65, {charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , 'A' } },
77+ { "simulateKeyUp( 65)" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 } },
7878
79- { "Module.injectKeyEvent('keydown', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 , 'A' } },
80- { "Module.injectKeyEvent ('keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
81- { "Module.injectKeyEvent('keyup', 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 , 'A' } },
79+ { "simulateKeyDown( 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_PRESS , -1 , 'A' } },
80+ { "simulateKeyEvent ('keypress', 65, {ctrlKey: true, charCode: 65})" , { 0 , 0.0 , 0.0 , -1 , -1 , -1 , -1 } },
81+ { "simulateKeyUp( 65, {ctrlKey: true})" , { 0 , 0.0 , 0.0 , GLFW_KEY_A , GLFW_RELEASE , -1 , 'A' } },
8282 #endif
8383};
8484
@@ -166,40 +166,6 @@ static void on_error(int error, const char *msg) {
166166int main () {
167167 unsigned int success = (1 << (sizeof (g_tests ) / sizeof (test_t ))) - 1 ; // (2^count)-1;
168168
169- emscripten_run_script (MULTILINE (
170- Module .injectMouseEvent = function (x , y , event_ , button ) {
171- var canvas = Module ['canvas' ];
172- var event = new MouseEvent (event_ , {
173- 'view' : window ,
174- 'bubbles' : true,
175- 'cancelable' : true,
176- 'screenX' : canvas .offsetLeft + x ,
177- 'screenY' : canvas .offsetTop + y ,
178- 'clientX' : canvas .offsetLeft + x ,
179- 'clientY' : canvas .offsetTop + y ,
180- 'button' : button
181- });
182- canvas .dispatchEvent (event );
183-
184- //var event = document.createEvent("MouseEvents");
185- //var canvas = Module['canvas'];
186- //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);
187- //canvas.dispatchEvent(event);
188- };
189-
190- Module .injectKeyEvent = function (type , keyCode , options ) {
191- // KeyboardEvent constructor always returns 0 keyCode on Chrome, so use generic events
192- //var keyboardEvent = new KeyboardEvent(type, Object.assign({ keyCode: keyCode}, options));
193- var keyboardEvent = document .createEventObject ?
194- document .createEventObject () : document .createEvent ('Events' );
195- keyboardEvent .initEvent (type , true, true);
196- keyboardEvent .keyCode = keyCode ;
197- keyboardEvent = Object .assign (keyboardEvent , options );
198-
199- canvas .dispatchEvent (keyboardEvent );
200- };
201- ));
202-
203169 glfwInit ();
204170
205171#if USE_GLFW == 2
0 commit comments