and when I put the mouse cursor the field and type a key, as well as the CP5 event happening, which I catch and process with controlEvent(), the regular keyPressed() also gets triggered with the key event. This seems strange, and undesirable! Is it necessary to have explicit logic (checking mouse pos not in CP5 area) to avoid this?
You can use the .isActive method on the controller to check if the cp5 controller is active. If you this method on the keyPressed event then you can shift between the desirable actions.
Check the example below
import controlP5.*;
ControlP5 cp5;
String textValue = "";
void setup() {
size(700,400);
PFont font = createFont("arial",20);
cp5 = new ControlP5(this);
cp5.addTextfield("input")
.setPosition(20,100)
.setSize(200,40)
.setFont(font)
.setFocus(true)
.setColor(color(255,0,0))
;
textFont(font);
}
void draw() {
background(0);
fill(255);
text(cp5.get(Textfield.class,"input").getText(), 360,130);
text(textValue, 360,180);
}
void keyPressed(){
if(!cp5.getController("input").isActive()) println(key); //if controller not active
else println("You press but I dont want to tell you the key");
}