mouseClicked(), mousePressed()... keyPressed(), keyReleased()... are they parallel?

Hello,

My question is When are theses functions processed / what is in draw() ?

(is it the same thing in Processing ?)

Is there some sort of parallelism (multiple threads) or not ? (I guess not)

I wonder !

thank you

:slight_smile:

Hello @EricRogerGarcia ,

“Wonder is the beginning of wisdom.” - Socrates

let events = []; // list of everything that happened (keeps growing)

function setup() {
  createCanvas(400, 600);
}

function draw() {
  background(245);a
}

function logEvent(msg) {
  // when an event happens, record frame + time + message
  let f = frameCount;      // which frame we are on
  let t = floor(millis()); // milliseconds since the sketch started

  events.push({ f: f, t: t, msg: msg }); // store it in the array
  console.log("[f " + f + "] [" + t + "ms] " + msg); // print to console
}

// these run automatically when you click or press keys
function mousePressed() { logEvent("mousePressed"); }
function mouseClicked() { logEvent("mouseClicked"); }
function keyPressed()   { logEvent("keyPressed: " + key); }
function keyReleased()  { logEvent("keyReleased: " + key); }

I have yet to scrutinize the output!
I did not give the references a thorough read… yet!
Often I will write code first to examine the behavior.

Have fun!

:)

:)) thanks :))

… but that doesn’t answer my question at all lol

What I would like to know is, when it happens compared to what happens in draw(): before draw(); after draw(), in parallel on another thread … in a given frame (but I may have expressed myself poorly: I understand English but when it comes to nuances, I inevitably make mistakes at times!).

I need to know for my code because depending on what is happening in draw(), the objects that are calculating or being displayed, they should not receive signals from the Observer pattern at any time which are sent at the initiative of these functions (if there were several threads for example)

:slight_smile:

PS. I’ve just downloaded 4.5.2. processing version, the new interface is great !