From 878598c83996052b32e024a69ce352732d446f95 Mon Sep 17 00:00:00 2001 From: Gnlow Date: Wed, 6 Dec 2023 12:58:46 +0900 Subject: [PATCH] impl: when_some_key_pressed --- src/Entry.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Entry.ts b/src/Entry.ts index a2acce7..da99486 100644 --- a/src/Entry.ts +++ b/src/Entry.ts @@ -171,6 +171,13 @@ export class Entry { when_run_button_click(f: () => Promise) { this.on("start", f) } + when_some_key_pressed(keyCode: string, f: () => Promise) { + document.body.addEventListener("keydown", e => { + if (e.keyCode == Number(keyCode)) { + f() + } + }) + } when_message_cast(messageId: string, f: () => Promise) { this.on(`message_${messageId}`, f) }