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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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);
}

chevron_right


Output:
display-pressed-released

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

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

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.