Skip to content

Commit

Permalink
add capture keys demo b00tc4mp#37
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbarzi committed Jan 30, 2025
1 parent 43d8c8c commit 42755ec
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions stuff/dom/capture-keys/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var x = 10
var y = 10

document.addEventListener('keydown', function (event) {
console.clear()

console.log(event.key)

if (event.key === 'ArrowUp')
y > 1 && y--
else if (event.key === 'ArrowDown')
y < 100 && y++
else if (event.key === 'ArrowLeft')
x > 1 && x--
else if (event.key === 'ArrowRight')
x < 100 && x++

console.log(x, y)

var canvas = ''

for (var i = 0; i < y; i++)
canvas += '\n'

for (var i = 0; i < x; i++)
canvas += ' '

canvas += '👻'

console.log(canvas)
})

0 comments on commit 42755ec

Please sign in to comment.