Friday, July 24, 2026
HomeLanguagesJavascriptp5.js Keyboard keyCode

p5.js Keyboard keyCode

The keyCode variable in p5.js always contains the key code of the key that is recently pressed. This key code is recommended to be used when finding out if the user if pressing a modifier key, like the Shift, Control, the Caps Lock key, or the Function keys.

Syntax: 

keyCode

The program below illustrates the keyCode variable in p5.js:
Example:
 

javascript




function setup() {
  createCanvas(400, 300);
}
  
function draw() {
  clear();
  textSize(18);
  fill("black");
  text("Press any key to see its keyCode", 60, 20);
  text("The name of the key pressed", 70, 60);
  
  textSize(52);
  fill("red");
  
  // Show the key that is recently pressed
  text(key, 170, 120);
  textSize(18);
  fill("black");
    
  text("The keyCode of the key pressed", 60, 160);
  textSize(52);
  fill("red");
  
  // Show the key code of the key that is
  // recently pressed
  text(keyCode, 160, 220);
}


Output:

keyCode-w-name

Reference: https://p5js.org/reference/#/p5/keyCode
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS