summaryrefslogtreecommitdiff
path: root/index.htm
diff options
context:
space:
mode:
Diffstat (limited to 'index.htm')
-rw-r--r--index.htm45
1 files changed, 32 insertions, 13 deletions
diff --git a/index.htm b/index.htm
index 3b1fd3b..2c42d74 100644
--- a/index.htm
+++ b/index.htm
@@ -98,10 +98,11 @@
if (!wait_for_events) {
if (sleep_duration > 0) {
+ let timeout = sleep_duration;
sleep_duration = 0;
setTimeout(() => {
window.requestAnimationFrame(animation_frame);
- }, sleep_duration);
+ }, timeout);
} else
window.requestAnimationFrame(animation_frame);
}
@@ -126,24 +127,42 @@
window.requestAnimationFrame(animation_frame);
});
- canvas.addEventListener("mouseenter", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
- });
+ let key_from_code = (code) => {
+ switch (code) {
+ case "KeyA": return 97;
+ }
+ return 0;
+ };
- canvas.addEventListener("mouseleave", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
- });
+ let mod_from_event = (ev) => {
+ let mod = 0;
+ if (ev.ctrlKey) mod |= 1;
+ if (ev.shiftKey) mod |= 2;
+ if (ev.altKey) mod |= 4;
+ if (ev.metaKey) mod |= 8;
+ return mod;
+ };
window.addEventListener("keydown", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
+ ev.preventDefault();
+ if (!ev.repeat) {
+ let mod = mod_from_event(ev);
+ let key = key_from_code(ev.code);
+ if (key != 0)
+ program.instance.exports.js_keydown(key, mod);
+ window.requestAnimationFrame(animation_frame);
+ }
});
window.addEventListener("keyup", (ev) => {
- console.log(ev);
- window.requestAnimationFrame(animation_frame);
+ ev.preventDefault();
+ if (!ev.repeat) {
+ let mod = mod_from_event(ev);
+ let key = key_from_code(ev.code);
+ if (key != 0)
+ program.instance.exports.js_keyup(key, mod);
+ window.requestAnimationFrame(animation_frame);
+ }
});
window.requestAnimationFrame(animation_frame);