From ee835a606fcaf4a656eaf70e78403ff598397f2f Mon Sep 17 00:00:00 2001 From: Victoria Lee Date: Sat, 26 Aug 2023 14:32:31 -0700 Subject: [PATCH 1/2] logs button presses basic --- index.html | 4 ++++ listening.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 97a5468..9e368ab 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,10 @@
+ + + +
diff --git a/listening.js b/listening.js index eb6885e..3094565 100644 --- a/listening.js +++ b/listening.js @@ -1,4 +1,9 @@ console.log("test") const listener = document.getElementById("listener") -listener.addEventListener("keypress", (event) => console.log(event.key)) +listener.addEventListener("keypress", (e) => { + if (e.key == "w" || e.key == "a" || e.key == "s" || e.key == "d") { + event.preventDefault(); + document.getElementById(e.key).click(); + console.log(e.key) + }}) /* document.addEventListener("keypress", (event) => console.log(event.key)) */ \ No newline at end of file From 565852cab8fc5fc442aaa91f12255129dd88f6cf Mon Sep 17 00:00:00 2001 From: Victoria Lee Date: Sat, 26 Aug 2023 14:41:45 -0700 Subject: [PATCH 2/2] not working --- index.html | 8 ++++---- listening.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 9e368ab..889022f 100644 --- a/index.html +++ b/index.html @@ -16,10 +16,10 @@
- - - - + + + +
diff --git a/listening.js b/listening.js index 3094565..8bd647a 100644 --- a/listening.js +++ b/listening.js @@ -3,7 +3,12 @@ const listener = document.getElementById("listener") listener.addEventListener("keypress", (e) => { if (e.key == "w" || e.key == "a" || e.key == "s" || e.key == "d") { event.preventDefault(); - document.getElementById(e.key).click(); - console.log(e.key) + const id = e.key + document.getElementById('w').click(); + clicked(id) }}) -/* document.addEventListener("keypress", (event) => console.log(event.key)) */ \ No newline at end of file +/* document.addEventListener("keypress", (event) => console.log(event.key)) */ + +function clicked(id) { + console.log(id) +} \ No newline at end of file