Skip to content

Commit e0215ca

Browse files
committed
[test] Unify fake events system. NFC
1 parent 475eeda commit e0215ca

12 files changed

+126
-152
lines changed

test/browser/fake_events.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,57 @@
22
* Helper function used in browser tests to simulate HTML5 events
33
*/
44

5-
function simulateKeyEvent(eventType, keyCode, code) {
5+
function simulateKeyEvent(target, eventType, keyCode, code) {
66
var props = { keyCode, charCode: keyCode, view: window, bubbles: true, cancelable: true };
77
if (code) props['code'] = code;
88
var event = new KeyboardEvent(eventType, props);
9-
return document.dispatchEvent(event);
9+
return target.dispatchEvent(event);
1010
}
1111

12-
function simulateKeyDown(keyCode, code = undefined) {
13-
var doDefault = simulateKeyEvent('keydown', keyCode, code);
12+
function simulateKeyDown(target, keyCode, code = undefined) {
13+
var doDefault = simulateKeyEvent(target, 'keydown', keyCode, code);
1414
// As long as not handler called `preventDefault` we also send a keypress
1515
// event.
1616
if (doDefault) {
17-
simulateKeyEvent('keypress', keyCode, code);
17+
simulateKeyEvent(target, 'keypress', keyCode, code);
1818
}
1919
}
2020

21-
function simulateKeyUp(keyCode, code = undefined) {
22-
simulateKeyEvent('keyup', keyCode, code);
21+
function simulateKeyUp(target, keyCode, code = undefined) {
22+
simulateKeyEvent(target, 'keyup', keyCode, code);
2323
}
2424

25-
function simulateMouseEvent(x, y, button, absolute) {
25+
function simulateKeyDownUp(target, keyCode, code = undefined) {
26+
simulateKeyDown(target, keyCode, code);
27+
simulateKeyUp(target, keyCode, code);
28+
}
29+
30+
function simulateMouseEvent(eventType, x, y, button, absolute) {
2631
if (!absolute) {
2732
x += Module['canvas'].offsetLeft;
2833
y += Module['canvas'].offsetTop;
2934
}
3035
var event = document.createEvent("MouseEvents");
31-
if (button >= 0) {
32-
var event1 = document.createEvent("MouseEvents");
33-
event1.initMouseEvent('mousedown', true, true, window,
34-
1, x, y, x, y,
35-
0, 0, 0, 0,
36-
button, null);
37-
Module['canvas'].dispatchEvent(event1);
38-
var event2 = document.createEvent("MouseEvents");
39-
event2.initMouseEvent('mouseup', true, true, window,
40-
1, x, y, x, y,
41-
0, 0, 0, 0,
42-
button, null);
43-
Module['canvas'].dispatchEvent(event2);
44-
} else {
45-
var event1 = document.createEvent("MouseEvents");
46-
event1.initMouseEvent('mousemove', true, true, window,
47-
1, x, y, x, y,
48-
0, 0, 0, 0,
49-
0, null);
50-
Module['canvas'].dispatchEvent(event1);
51-
}
36+
event.initMouseEvent(eventType, true, true, window,
37+
1, x, y, x, y,
38+
0, 0, 0, 0,
39+
button, null);
40+
Module['canvas'].dispatchEvent(event);
41+
}
42+
43+
function simulateMouseDown(x, y, button, absolute) {
44+
simulateMouseEvent('mousedown', x, y, button, absolute);
45+
}
46+
47+
function simulateMouseUp(x, y, button, absolute) {
48+
simulateMouseEvent('mouseup', x, y, button, absolute);
49+
}
50+
51+
function simulateMouseMove(x, y, button, absolute) {
52+
simulateMouseEvent('mousemove', x, y, button, absolute);
53+
}
54+
55+
function simulateMouseClick(x, y, button, absolute) {
56+
simulateMouseDown(x, y, button, absolute);
57+
simulateMouseUp(x, y, button, absolute);
5258
}

test/canvas_focus.c renamed to test/browser/test_canvas_focus.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userDat
2020
}
2121

2222
int main() {
23+
printf("in main\n");;
2324
emscripten_set_keypress_callback("#canvas", 0, 1, key_callback);
2425
EM_ASM({
25-
var event = new KeyboardEvent("keypress", { 'keyCode': 38, 'charCode': 38, 'view': window, 'bubbles': true, 'cancelable': true });
26-
// Focus, then send an event, same as if the user clicked on it for focus.
2726
Module.canvas.focus();
28-
document.activeElement.dispatchEvent(event);
27+
simulateKeyEvent(Module.canvas, "keypress", 38);
2928
});
3029
emscripten_exit_with_live_runtime();
3130
__builtin_trap();

test/browser/test_glfw_events.c

Lines changed: 41 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,52 @@
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

@@ -182,45 +182,11 @@
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
@@ -297,4 +263,4 @@
297263

298264
return 0;
299265
}
300-
#endif
266+
#endif

test/browser/test_sdl2_key.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ int main(int argc, char **argv) {
6262

6363
SDL_StartTextInput();
6464

65-
emscripten_run_script("simulateKeyDown(38, 'ArrowUp'); simulateKeyUp(38, 'ArrowUp')"); // up
66-
emscripten_run_script("simulateKeyDown(40, 'ArrowDown'); simulateKeyUp(40, 'ArrowDown')"); // down
67-
emscripten_run_script("simulateKeyDown(37, 'ArrowLeft'); simulateKeyUp(37, 'ArrowLeft');"); // left
68-
emscripten_run_script("simulateKeyDown(39, 'ArrowRight');simulateKeyUp(39, 'ArrowRight');"); // right
69-
emscripten_run_script("simulateKeyDown(65, 'KeyA'); simulateKeyUp(65, 'KeyA');"); // a
70-
emscripten_run_script("simulateKeyDown(66, 'KeyB'); simulateKeyUp(66, 'KeyB');"); // b
71-
emscripten_run_script("simulateKeyDown(100, 'Numpad4'); simulateKeyUp(100, 'Numpad4');"); // trigger the end
65+
emscripten_run_script("simulateKeyDownUp(document, 38, 'ArrowUp')");
66+
emscripten_run_script("simulateKeyDownUp(document, 40, 'ArrowDown')");
67+
emscripten_run_script("simulateKeyDownUp(document, 37, 'ArrowLeft')");
68+
emscripten_run_script("simulateKeyDownUp(document, 39, 'ArrowRight')");
69+
emscripten_run_script("simulateKeyDownUp(document, 65, 'KeyA')");
70+
emscripten_run_script("simulateKeyDownUp(document, 66, 'KeyB')");
71+
emscripten_run_script("simulateKeyDownUp(document, 100, 'Numpad4')"); // trigger the end
7272

7373
emscripten_set_main_loop(pump_events, 3, 0);
7474
return 99;

test/browser/test_sdl2_mouse.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ int main() {
9090
int absolute = false;
9191
#endif
9292

93-
EM_ASM(simulateMouseEvent(10, 20, -1, $0), absolute); // move from 0,0 to 10,20
94-
EM_ASM(simulateMouseEvent(10, 20, 0, $0), absolute); // click
95-
EM_ASM(simulateMouseEvent(10, 20, 0, $0), absolute); // click some more, but this one should be ignored through PeepEvent
96-
EM_ASM(simulateMouseEvent(30, 70, -1, $0), absolute); // move some more
97-
EM_ASM(simulateMouseEvent(30, 70, 1, $0), absolute); // trigger the end
93+
EM_ASM(simulateMouseMove(10, 20, $0), absolute); // move from 0,0 to 10,20
94+
EM_ASM(simulateMouseClick(10, 20, 0, $0), absolute); // click
95+
EM_ASM(simulateMouseClick(10, 20, 0, $0), absolute); // click some more, but this one should be ignored through PeepEvent
96+
EM_ASM(simulateMouseMove(30, 70, $0), absolute); // move some more
97+
EM_ASM(simulateMouseClick(30, 70, 1, $0), absolute); // trigger the end
9898

9999
emscripten_set_main_loop(one, 0, 0);
100100
}

test/browser/test_sdl2_pumpevents.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ int main(int argc, char *argv[])
5656
SDL_Window *window;
5757
SDL_CreateWindow("window", 0, 0, 600, 450, 0);
5858

59-
emscripten_run_script("simulateKeyDown(37, 'ArrowLeft');"); // left
59+
emscripten_run_script("simulateKeyDown(document, 37, 'ArrowLeft');"); // left
6060
loop1();
61-
emscripten_run_script("simulateKeyDown(39, 'ArrowRight');"); // right
61+
emscripten_run_script("simulateKeyDown(document, 39, 'ArrowRight');"); // right
6262
loop2();
63-
emscripten_run_script("simulateKeyDown(65, 'KeyA');"); // A
63+
emscripten_run_script("simulateKeyDown(document, 65, 'KeyA');"); // A
6464
alphakey();
6565
return 0;
6666
}

test/browser/test_sdl2_text.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ int main() {
3737
SDL_CreateWindow("window", 0, 0, 600, 450, 0);
3838
SDL_StartTextInput();
3939

40-
emscripten_run_script("simulateKeyDown('a'.charCodeAt(0))");
41-
emscripten_run_script("simulateKeyDown('A'.charCodeAt(0))");
40+
emscripten_run_script("simulateKeyDown(document, 'a'.charCodeAt(0))");
41+
emscripten_run_script("simulateKeyDown(document, 'A'.charCodeAt(0))");
4242

4343
one();
4444

test/browser/test_sdl_mouse.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ int main() {
7676
int absolute = false;
7777
#endif
7878

79-
EM_ASM(simulateMouseEvent(10, 20, -1, $0), absolute); // move from 0,0 to 10,20
80-
EM_ASM(simulateMouseEvent(10, 20, 0, $0), absolute); // click
81-
EM_ASM(simulateMouseEvent(10, 20, 0, $0), absolute); // click some more, but this one should be ignored through PeepEvent
82-
EM_ASM(simulateMouseEvent(30, 77, -1, $0), absolute); // move some more
83-
EM_ASM(simulateMouseEvent(30, 77, 1, $0), absolute); // trigger the end
79+
EM_ASM(simulateMouseMove(10, 20, $0), absolute); // move from 0,0 to 10,20
80+
EM_ASM(simulateMouseClick(10, 20, 0, $0), absolute); // click
81+
EM_ASM(simulateMouseClick(10, 20, 0, $0), absolute); // click some more, but this one should be ignored through PeepEvent
82+
EM_ASM(simulateMouseMove(30, 77, $0), absolute); // move some more
83+
EM_ASM(simulateMouseClick(30, 77, 1, $0), absolute); // trigger the end
8484

8585
emscripten_set_main_loop(one, 0, 0);
8686
}

test/browser/test_sdl_pumpevents.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ int main(int argc, char *argv[]) {
5454
SDL_Init(SDL_INIT_EVERYTHING);
5555
SDL_SetVideoMode(600, 400, 32, SDL_SWSURFACE);
5656

57-
emscripten_run_script("simulateKeyDown(37);"); // left
57+
emscripten_run_script("simulateKeyDown(document, 37);"); // left
5858
loop1();
59-
emscripten_run_script("simulateKeyDown(39);"); // right
59+
emscripten_run_script("simulateKeyDown(document, 39);"); // right
6060
loop2();
61-
emscripten_run_script("simulateKeyDown(65);"); // A
61+
emscripten_run_script("simulateKeyDown(document, 65);"); // A
6262
alphakey();
6363
return 0;
6464
}

test/browser/test_sdl_text.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ int main() {
3838
SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
3939
SDL_StartTextInput();
4040

41-
emscripten_run_script("simulateKeyDown('a'.charCodeAt(0))");
42-
emscripten_run_script("simulateKeyDown('A'.charCodeAt(0))");
41+
emscripten_run_script("simulateKeyDown(document, 'a'.charCodeAt(0))");
42+
emscripten_run_script("simulateKeyDown(document, 'A'.charCodeAt(0))");
4343

4444
emscripten_exit_with_live_runtime();
4545
}

0 commit comments

Comments
 (0)