Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

p5.js | keyReleased() Function

  • Last Updated : 27 Mar, 2020

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!