summaryrefslogtreecommitdiff
path: root/index.htm
diff options
context:
space:
mode:
Diffstat (limited to 'index.htm')
-rw-r--r--index.htm73
1 files changed, 56 insertions, 17 deletions
diff --git a/index.htm b/index.htm
index 33d6c2d..b529d83 100644
--- a/index.htm
+++ b/index.htm
@@ -10,8 +10,8 @@
<canvas style="margin: 0; width: 100%; height: 100%;" id="frame" oncontextmenu="event.preventDefault()"></canvas>
<script type="worklet">
registerProcessor(
- 'Sound_Node',
- class Sound_Ring extends AudioWorkletProcessor {
+ "Sound_Node",
+ class Sound_Node extends AudioWorkletProcessor {
constructor(options) {
super();
@@ -33,7 +33,7 @@
fd_seek : () => { throw new Error("Unexpected fd_seek call"); },
},
env : {
- p_clipboard_write : (size, text) => {
+ p_clipboard_write_impl : (size, text) => {
let text_buffer = new ArrayBuffer(size);
new Uint8Array(text_buffer).set(new Uint8Array(this.memory_buffer, text, size));
@@ -116,7 +116,7 @@
if (this.program === undefined)
return;
- this.program.exports.js_keydown(ev.key, ev.mod);
+ this.program.exports.js_keydown(ev.key, ev.mod, ev.ch);
},
keyup : (ev) => {
@@ -125,6 +125,18 @@
this.program.exports.js_keyup(ev.key, ev.mod);
},
+
+ paste : (ev) => {
+ if (this.program === undefined)
+ return;
+
+ let address = this.program.exports.js_clipboard_buffer(ev.bytes.length);
+ let len = this.program.exports.js_clipboard_size();
+
+ new Uint8Array(this.memory_buffer, address, len).set(ev.bytes.subarray(0, len));
+
+ this.program.exports.js_keydown(ev.key, ev.mod, ev.ch);
+ },
};
this.port.onmessage = (ev) => {
@@ -162,6 +174,8 @@
);
</script>
<script type="text/javascript">
+ const KEY_PASTE = 118;
+
let key_map = {
"Backspace" : 8,
"Tab" : 9,
@@ -229,7 +243,7 @@
"KeyS" : 115,
"KeyT" : 116,
"KeyU" : 117,
- "KeyV" : 118,
+ "KeyV" : KEY_PASTE,
"KeyW" : 119,
"KeyX" : 120,
"KeyY" : 121,
@@ -276,6 +290,12 @@
return mod;
};
+ function char_from_event(ev) {
+ if (ev.key.length != 1)
+ return 0;
+ return ev.key.charCodeAt(0);
+ }
+
async function run(attrs) {
let sound_sample_rate = 44100; // TODO
let sound_num_channels = 2; // TODO
@@ -293,6 +313,9 @@
let sound_context;
let sound_node;
+ let paste_mod = 0;
+ let paste_ch = 0;
+
canvas = attrs.canvas;
context = canvas.getContext("2d");
@@ -378,7 +401,6 @@
frame : (ev) => {
pixels_buffer = ev.pixels_buffer;
- let pixels = new Uint8Array(pixels_buffer);
}
};
@@ -428,23 +450,26 @@
});
window.addEventListener("keydown", (ev) => {
- ev.preventDefault();
if (!sound_ready)
return;
if (ev.repeat)
return;
- let mod = mod_from_event(ev);
let key = key_from_code(ev.code);
if (key == 0)
return;
+ let mod = mod_from_event(ev);
+ let ch = char_from_event(ev);
- console.log(ev);
-
- sound_node.port.postMessage({
- id : "keydown",
- mod : mod,
- key : key,
- });
+ if (ev.ctrlKey && key == KEY_PASTE) {
+ paste_mod = mod;
+ paste_ch = ch;
+ } else
+ sound_node.port.postMessage({
+ id : "keydown",
+ mod : mod,
+ key : key,
+ ch : ch,
+ });
});
window.addEventListener("keyup", (ev) => {
@@ -453,15 +478,29 @@
return;
if (ev.repeat)
return;
- let mod = mod_from_event(ev);
let key = key_from_code(ev.code);
if (key == 0)
return;
+ let mod = mod_from_event(ev);
sound_node.port.postMessage({
id : "keyup",
- mod : mod,
key : key,
+ mod : mod,
+ });
+ });
+
+ window.addEventListener("paste", (ev) => {
+ ev.preventDefault();
+ if (!sound_ready)
+ return;
+
+ sound_node.port.postMessage({
+ id : "paste",
+ bytes : new TextEncoder("utf-8").encode(ev.clipboardData.getData("text")),
+ mod : paste_mod,
+ key : KEY_PASTE,
+ ch : paste_ch,
});
});
}