From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
KeyPressed event function - JavaScript Tutorial
From the course: Coding for Visual Learners: Learning JavaScript from Scratch
KeyPressed event function
- [Instructor] There are a lot of other event functions. A complete list can be found under this link. One other event function that might be worth learning about is the keyPressed function. As the name implies, keyPressed function gets triggered every time a key is pressed. Let's quickly test how it works in a brand new program. So I'm going to delete all this code. Let's delete everything except maybe for the background declaration from the draw function. And let's delete this mouse is pressed function too. So I'm going to set my background to a simple color like gray. And delete the comment as well. And delete this rectMode function too. And here I will declare the keyPressed function and just to make sure that it is working, let's console.log something inside it, something like pressed. So now whenever I click a button on my keyboard, I can see the pressed message getting logged. Now that we have this,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.