Saturday, October 25, 2025
HomeLanguagesJavascriptp5.js keyReleased() Function

p5.js keyReleased() Function

The keyReleased() function is invoked whenever a key is called every time when a key is pressed. The most recently typed ASCII key is stored into the ‘key’ variable, however, it does not distinguish between uppercase and lowercase characters. The non-ASCII characters can be accessed in the ‘keyCode’ variable with their respective codes.

Different browsers may have their own default behavior attached to some of the keys. This can be prevented by adding “return false” to the end of the function.

Syntax:

keyReleased()

Parameters: This method does not accept any parameters.

Below examples illustrate the keyReleased() function in p5.js:

Example:




function setup() {
  createCanvas(600, 200);
  textSize(20);
  text("Press any key to check if "
        + "it is being pressed or "
        + "released", 10, 20);
}
   
function keyPressed() {
  clear();
  textSize(20);
  text("Press any key to check if "
        + "it is being pressed or "
        + "released", 10, 20);
  textSize(30);
    
  text("You are pressing: " 
        + key, 20, 100);
}
   
function keyReleased() {
  clear();
  textSize(20);
  text("Press any key to check if "
        + "it is being pressed or "
        + "released", 10, 20);
  textSize(30);
    
  text("You released: "
        + key, 20, 100);
}


Output:
display-pressed-released

Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

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

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!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS