PressDo or keyPressed Error

Hello everyone,
I developed a sketch on interactive typography. I wanted to create a keyboard-sensitive interaction with PressDo in the work whose codes I share with you below. However, “ArrowUp” and “ArrowDown” do not work and all commands work with “ArrowRight” and “ArrowLeft”.
What I want to do:
ArrowUp to increase the number of circles, ArrowDown to decrease the number of circles.
ArrowRight to increase the circle size and ArrowDown to decrease the circle size.
Can you help me with this?
<
import { createNoise4D } from ‘https://cdn.skypack.dev/simplex-noise@4.0.0
import { mountFlex } from “https://cdn.jsdelivr.net/npm/p5.flex@0.0.0/src/p5.flex.mjs
import { PressDo } from “./Control.js”

mountFlex(p5)

let font;
let points = ;
const speed = 0.02;
const CIRCLE_RADIUS = 200;
let amount = 200;
let circleSize = 2;
let circleCount = 10;
let isCurve = true;
let isShowCircle = true;
let angleOffset;

new p5((p) => {
const simplexNoiseSeed = p.random()
const noise4D = createNoise4D(()=>simplexNoiseSeed)

p.preload = () => {
    font = p.loadFont('NotoSansThin.ttf');
}

p.setup = () => {
    p.createCanvas(600, 600)
    p.pixelDensity(4)
    p.stroke(255)
    p.noFill()

    let fontSize = 500;
    p.textFont(font);
    p.textSize(fontSize);
    let message = "A";
    let txtPoints = font.textToPoints(message, p.width / 4, p.height / 1.5, fontSize, {
        sampleFactor: 0.1
    });
		  let averageX = 0;
    let averageY = 0;
    for (let i = 0; i < txtPoints.length; i++) {
    averageX += txtPoints[i].x;
    averageY += txtPoints[i].y;
    }
    averageX /= txtPoints.length;
    averageY /= txtPoints.length;

    for (let i = 0; i < txtPoints.length; i++) {
        points.push(p.createVector(txtPoints[i].x - averageX, txtPoints[i].y - averageY));
    }

    angleOffset = p.PI / 1.5;
    
    PressDo("c", () => { isCurve = !isCurve })
    PressDo("s", () => { isShowCircle = !isShowCircle })
    PressDo("ArrowUp", () => { circleSize = p.max(1, circleSize + 1) });
    PressDo("ArrowDown", () => { circleSize = p.max(1, circleSize - 1) });
    PressDo("ArrowRight", () => { circleCount += 1 });
    PressDo("ArrowLeft", () => { circleCount = p.max(1, circleCount - 1) });
    p.flex()
}

p.draw = () => {
    const t = p.frameCount * speed;
    p.background(0);
    const noiseWeight = p.map(p.mouseX, 0, p.width, -100, 100, true);
    const angle = p.map(p.mouseY, 0, p.height, -p.PI, p.PI, true) + angleOffset;
    
    p.push();
    p.translate(p.width / 2, p.height / 2);
    //p.rotate(angle);

    drawNoboFromPoints(points, CIRCLE_RADIUS, noiseWeight, amount, circleSize, circleCount, t);
    p.pop();
}

const drawNoboFromPoints = (points, radius, noiseWeight, amount, circleSize, t) => {
    p.push();
    p.beginShape();
    for (let i = 0; i < points.length; i++) {
        const x = points[i].x;
        const y = points[i].y;
        const nx = noise4D(x + 100, y + 200, p.cos(t), p.sin(t)) * noiseWeight;
        const ny = noise4D(x + 300, y + 400, p.cos(t), p.sin(t)) * noiseWeight;
        if (isCurve) p.curveVertex(x + nx, y + ny);
        else p.vertex(x + nx, y + ny);
        if (isShowCircle) p.ellipse(x + nx, y + ny, circleSize, circleSize);
    }
    p.endShape();
    p.pop();
}

});

There is a demo here which might be helpful:
https://p5js.org/reference/#/p5/keyPressed

I was unable to get the posted code to run.

The following source code demonstrates using the arrow keys in instance mode:

const s = p => {
  let x = 100;
  let y = 100;
  let value = 85;
  
  p.setup = function() {
    p.createCanvas(400, 400);
    p.background(209);
  };

  p.draw = function() {    
    p.fill(value);
    p.rect(x, y, 50, 50);
  };
  
  p.keyPressed = function(){
    if (p.keyCode === p.LEFT_ARROW) {
    value = 255;
  } else if (p.keyCode === p.RIGHT_ARROW) {
    value = 0;
  } else if (p.keyCode === p.UP_ARROW) {
    value = 150;
  } else if (p.keyCode === p.DOWN_ARROW) {
    value = 100;
  }
  }
  
};

new p5(s); // invoke p5

Any JS file which includes either keywords import or export must be loaded as a module within a <script> tag or imported from another file.

“index.html”:

<script defer src=https://cdn.JsDelivr.net/npm/p5></script>
<script type=module src=sketch.mjs></script>

Thanks. p5.js WebEditor likes src and type in double quotes. I recopied/pasted his post again (can you edit his formatting?) and made the additions to index.html. I’m left with this error:

Do they really expect someone to copy/paste his entire post into the index.html??

Only moderators and up can do that, sorry.

Sorry, I guess my quote was not well written. :confounded:
I’ve meant inside the <script> tag itself via its attribute type, not its body:

Well, just add them! :man_shrugging: I’ve omitted them for simplicity & b/c browsers do well w/o them.
Take a look at this “js.html” file as an example of loading a JS module via <script>:
https://GoToLoop.PyScriptApps.com/ramer-douglas-peucker/latest/js.html
https://PyScript.com/@gotoloop/ramer-douglas-peucker

Can you run his code? I only mentioned the quotes for the next person who has the same problem.

None of those pyscript references work for me; obviously something I don’t know/understand.

We don’t have dependence module: “Control.js”

For a project w/ multiple files and/or assets, it’s better to use a hosting service.

Check if there’s any ad-blocking addon playing out.
Make sure to be using an up-to-date browser.

The demo now sort of runs with one error: ‘noise4D is not defined’. Just see a black screen. Had to use a different font (Inconsolata.otf). Ripped out PressDo and added p.keyPressed as described in the example I posted. For certain ‘instance mode’ is an advanced topic as the Reference states. If this is ‘homework’ they didn’t start with something easy.

Addendum:
Adding p.keyPressed as shown in a previous post does indeed allow trapping of all the arrow keys, not just left and right as indicated in the initial post. This should be the solution.

Not advanced but an added nuisance of requiring p. to access all p5js API.

Example: Rather than just background(0) or mouseX we need p.background(0) or p.mouseX.