Path: blob/main/test/browser/test_canvas_focus.c
4150 views
/*1* Copyright 2017 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <emscripten/html5.h>8#include <emscripten/key_codes.h>9#include <emscripten.h>10#include <stdio.h>11#include <string.h>1213bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData) {14static int i = 0;15printf("key_callback %d\n", i);16i++;17emscripten_force_exit(0);18return 0;19}2021int main() {22emscripten_set_keypress_callback("#canvas", 0, 1, key_callback);23EM_ASM({24Module.canvas.focus();25simulateKeyEvent("keypress", 38, undefined, undefined, /*target=*/document.activeElement);26});27emscripten_exit_with_live_runtime();28__builtin_trap();29}303132