Open In App

p5.js keyReleased() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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


Last Updated : 18 Aug, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads