keyPressed(event) usage

In the keyPressed documentation one of the usages listed under Syntax is keyPressed(event).

My expectation is that you could write the function as keyPressed(Event event), but that doesn’t seem to be correct.

I anyone able to clear up what the docs are driving at and example of this kind of usage?

Ditto for mouseClicked or any function in the format function(event) in the documentation.

it’s pretty much like in the examples on the pages you were referring to

void keyPressed() {
  if (key == '0') {
    value = 255;
  }
}

and

void mouseClicked() {
  if (value == 0) {
    value = 255;
  } else {
    value = 0;
  }
}

keyPressed(event) is highly suggestive that these functions pass an argument event

To clarify, what does event refer to in this context?

1 Like

I would guess a KeyEvent object from reading the Java documentation.

This checks out:

void keyPressed(KeyEvent event) {
  println(event);  
}

Thank you.

What a weird way to convey that in the documentation. It seems odd not to include as KeyEvent has a couple of useful methods.

I’ll wing a pull request on the documentation with something a little more explanatory.

1 Like
  1. PApplet
  2. KeyEvent
  3. Event

Number 1 is the ticket.

Still a little too squirrelled away though.

Plus it doesn’t address the weird way of expressing the syntax