fix: buggy space bar control
This commit is contained in:
@@ -106,22 +106,25 @@ function fadeOut() {
|
|||||||
* Allow audio to be played/paused using the space bar
|
* Allow audio to be played/paused using the space bar
|
||||||
*/
|
*/
|
||||||
function enableSpaceBarControl() {
|
function enableSpaceBarControl() {
|
||||||
|
let isDown = false;
|
||||||
document.addEventListener("keydown", (event) => {
|
document.addEventListener("keydown", (event) => {
|
||||||
|
if (isDown) return;
|
||||||
if (event.code === "Space") {
|
if (event.code === "Space") {
|
||||||
|
isDown = true;
|
||||||
playBtn.classList.add("button-active");
|
playBtn.classList.add("button-active");
|
||||||
playBtn.dispatchEvent(new MouseEvent("mousedown"));
|
|
||||||
clickAudio.play();
|
clickAudio.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener("keyup", (event) => {
|
document.addEventListener("keyup", (event) => {
|
||||||
|
isDown = false;
|
||||||
if (event.code === "Space") {
|
if (event.code === "Space") {
|
||||||
playBtn.classList.remove("button-active");
|
playBtn.classList.remove("button-active");
|
||||||
clickReleaseAudio.play();
|
clickReleaseAudio.play();
|
||||||
}
|
if (isPlaying) {
|
||||||
});
|
pauseAudio();
|
||||||
document.addEventListener("keypress", (event) => {
|
} else {
|
||||||
if (event.code === "Space") {
|
playAudio();
|
||||||
playBtn.click();
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user