Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/test_canvas_focus.c
4150 views
1
/*
2
* Copyright 2017 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
8
#include <emscripten/html5.h>
9
#include <emscripten/key_codes.h>
10
#include <emscripten.h>
11
#include <stdio.h>
12
#include <string.h>
13
14
bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData) {
15
static int i = 0;
16
printf("key_callback %d\n", i);
17
i++;
18
emscripten_force_exit(0);
19
return 0;
20
}
21
22
int main() {
23
emscripten_set_keypress_callback("#canvas", 0, 1, key_callback);
24
EM_ASM({
25
Module.canvas.focus();
26
simulateKeyEvent("keypress", 38, undefined, undefined, /*target=*/document.activeElement);
27
});
28
emscripten_exit_with_live_runtime();
29
__builtin_trap();
30
}
31
32