forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not prevent default handling for keydown event except for backspac…
…e and tab.
- Loading branch information
Showing
4 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <stdio.h> | ||
#include <emscripten.h> | ||
#include <html5.h> | ||
static int result = 1; | ||
|
||
// The event handler functions can return 1 to suppress the event and disable the default action. That calls event.preventDefault(); | ||
// Returning 0 signals that the event was not consumed by the code, and will allow the event to pass on and bubble up normally. | ||
extern "C" | ||
{ | ||
EM_BOOL keydown_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData) | ||
{ | ||
if ((e->keyCode == 65) || (e->keyCode == 8)) | ||
{ | ||
result *= 2; | ||
} | ||
else | ||
{ | ||
REPORT_RESULT(); | ||
emscripten_run_script("throw 'done'"); | ||
} | ||
return 0; | ||
} | ||
} | ||
|
||
extern "C" | ||
{ | ||
EM_BOOL keypress_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData) | ||
{ | ||
result *= 3; | ||
return 0; | ||
} | ||
} | ||
|
||
extern "C" | ||
{ | ||
EM_BOOL keyup_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData) | ||
{ | ||
if ((e->keyCode == 65) || (e->keyCode == 8)) | ||
{ | ||
result *= 5; | ||
} | ||
return 0; | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
printf("main argc:%d\n", argc); | ||
|
||
emscripten_set_keydown_callback("#document", 0, 1, keydown_callback); | ||
emscripten_set_keypress_callback("#document", 0, 1, keypress_callback); | ||
emscripten_set_keyup_callback("#document", 0, 1, keyup_callback); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters