When working with the p5 javascript library, there is a convenient built-in function called {key}
that captures the key you press. For instance, using text(${key},200,200)
will display the key pressed at position 200, 200 on the canvas. If I were to store this key value in an array and then retrieve it using console.log()
, the output would be: Object {key: "a"}. So if you input "A", the letter A would be stored in the array. However, when trying to display this text using
text(Array_Of_Text[0],Xposition,Yposition);
you might just see "Object, Object" on the screen. This indicates that I need to somehow extract the actual value from the object, but I am unsure of how to accomplish this.
let Text = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
text(Text[0],200,200);
console.log(Text[0])
}
function keyPressed()
{
Text.push({key})
}