Skip to content

Commit

Permalink
Merge pull request #46 from a-khushal/feature/pan-Using-Space-key
Browse files Browse the repository at this point in the history
PR 41 broke the functionality, here's a fix to it
  • Loading branch information
dhruvpatidar359 authored May 15, 2024
2 parents d4356b3 + 5fdba6f commit 1b823b2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions components/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const Canvas = () => {


useEffect(()=>{
const canvas = document.getElementById("canvas")
const handleKeyDown = (event) => {
setKeys(keys => new Set(keys).add(event.key));
}
Expand All @@ -126,11 +127,11 @@ const Canvas = () => {
};

// console.log(keys)
window.addEventListener("keydown", handleKeyDown);
window.addEventListener("keyup", handleKeyUp);
canvas.addEventListener("keydown", handleKeyDown);
canvas.addEventListener("keyup", handleKeyUp);
return () => {
window.removeEventListener("keydown", handleKeyDown);
window.removeEventListener("keyup", handleKeyUp);
canvas.removeEventListener("keydown", handleKeyDown);
canvas.removeEventListener("keyup", handleKeyUp);
};
},[keys])

Expand Down

0 comments on commit 1b823b2

Please sign in to comment.