Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

p5.js | input() Function

  • Last Updated : 17 Jan, 2020

The input() function is invoked whenever user input is detected on the element. It can be used to detect keystrokes or changes in the values of a slider. It can also be used to attach an event listener to an element.



Parameters: This function accepts a single parameter as mentioned above and described below.

  • fxn: This is the callback function that would be called whenever input is detected. It can be passed ‘false’, which would prevent the previous firing function to stop firing.

Below example illustrates the input() function in p5.js:


function setup() {
  createCanvas(600, 300);
  text("Write in the input box to change the text", 10, 20);
  // create input box
  let inputElem = createInput('');
  inputElem.position(20, 40)
function onInput() {
  text("Write in the input box to change the text", 10, 20);
  rect(0, 80, 600, 100)
  // get the text entered
  text(this.value(), 20, 120)


Online editor:
Environment Setup:


Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!