Created
April 13, 2014 04:14
-
-
Save usagi/10568899 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <iostream> | |
| #include <queue> | |
| #include <emscripten/emscripten.h> | |
| #include <emscripten/bind.h> | |
| namespace | |
| { | |
| std::queue<unsigned int> keydown_buffer; | |
| auto cxx_keydown(unsigned int key_code) | |
| -> void | |
| { | |
| EM_ASM({ console.log("cxx_keydown") }); | |
| keydown_buffer.push(key_code); | |
| } | |
| EMSCRIPTEN_BINDINGS(my_module) | |
| { emscripten::function("cxx_keydown", &cxx_keydown); } | |
| } | |
| auto main() -> int | |
| { | |
| EM_ASM({ window.addEventListener("keydown", function(e){ Module.cxx_keydown(e.keyCode); }); }); | |
| emscripten_set_main_loop | |
| ( [] | |
| { | |
| while(!keydown_buffer.empty()) | |
| { | |
| std::cerr << keydown_buffer.front() << "\n"; | |
| keydown_buffer.pop(); | |
| } | |
| } | |
| , 100 | |
| , 1 | |
| ); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile:
em++ --bind -o emscripten_keydown_sample.out.html -std=c++11 emscripten_keydown_sample.cxx