A function that's called once when any key is released.
Declaring the function keyReleased()
sets a code block to run once automatically when the user releases any key:
function keyReleased() {
// Code to run.
}
The key and keyCode variables will be updated with the most recently released value when keyReleased()
is called by p5.js:
function keyReleased() {
if (key === 'c') {
// Code to run.
}
if (keyCode === ENTER) {
// Code to run.
}
}
The parameter, event
, is optional. keyReleased()
is always passed a KeyboardEvent object with properties that describe the key press event:
function keyReleased(event) {
// Code to run that uses the event.
console.log(event);
}
Browsers may have default behaviors attached to various key events. To prevent any default behavior for this event, add return false;
to the end of the function.
Examples
Syntax
keyReleased([event])
Parameters
optional KeyboardEvent
callback argument.
Related References
key
A String system variable that contains the value of the last key typed.
keyCode
A Number system variable that contains the code of the last key typed.
keyIsDown
Returns true if the key it’s checking is pressed and false if not.
keyIsPressed
A Boolean system variable that's true if any key is currently pressed and false if not.