Wednesday, July 3, 2024
HomeLanguagesJavascriptp5.js keyTyped() Function

p5.js keyTyped() Function

The keyTyped() function is invoked every time when a key is pressed, except for action keys like the directional arrow keys, Ctrl, Shift, Alt, Backspace and the Delete key. The most recently typed key is stored in the ‘key’ variable.

Note that, holding down a key may cause multiple keyTyped() calls. This is due to how the Operating System handles keypresses and depends on how the computer is configured. A browser may have its own default behavior attached to various keys which can be prevented by adding “return false” to the end of the method.

Syntax:

keyTyped()

Parameters: This method does not accept any parameters.

Below example illustrates the keyTyped() function in p5.js:

Example:




function setup() {
  createCanvas(600, 200);
  textSize(20);
  text("Press any key to display it on the screen", 10, 20);
  text("Any of the action keys would not be recognized", 10, 40);
}
  
function keyTyped() {
  clear();
  textSize(20);
  text("Press any key to display it on the screen", 10, 20);
  text("Any of the action keys would not be recognized", 10, 40);
  textSize(100);
  text(key, 100, 150);
}


Output:
display-typed

Environment Setup: https://www.neveropen.co.za/p5-js-soundfile-object-installation-and-methods/

Reference: https://p5js.org/reference/#/p5/keyTyped

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments