Learn to Code via Tutorials on Repl.it!

← Back to all posts
JavaScript KeyInput! (KeyDown)
PixiGem (219)

This tutorial, you'll learn how to use the JavaScript KeyInput, so let's get started!

for example, we'll create a simple webpage that has a red canvas, whenever we click 'B' on our keyboard, it changes to blue, and 'R' for red. (go to the below repl)

HTML

Cool! we just created our red canvas!

JavaScript -

first, we need to add an event listener to our webpage -

now, check for the key we press, every key on the keyboard has a code in javascript, here is the list of them -

http://gcctech.org/csc/javascript/javascript_keycodes.htm

that was very loooooong, now coming to the if statement, here is the code -

Upvote if you find this tutorial helpful :)

Comments
hotnewtop
NextLevel3 (0)

you have deserve more upvote for great information , I have learned JavaScript KeyInput. i also share very informative a <a href="https://bynext.com/2021/06/06/toonly-lifetime-dea">Toonly Lifetime</a>