The keyPressed() function is invoked whenever 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 character codes can be accessed in the ‘keyCode’ variable with their respective names.
Holding down a key may cause multiple keyPressed() 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. This can be prevented by adding “return false” to the end of the method.
Parameters: This method does not accept any parameters.
Below examples illustrate the keyPressed() function in p5.js:
Online editor: https://editor.p5js.org/
- How to get the function name inside a function in PHP ?
- PHP | Ds\Set add() Function
- p5.js | str() function
- CSS | hsl() Function
- PHP | each() Function
- PHP | Ds\Set xor() Function
- p5.js | tan() function
- p5.js | cos() function
- p5.js | log() function
- p5.js | sin() function
- p5.js | int() function
- PHP | ord() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.