Drawing a line in processing after a region of the screen has been pressed and the mouse is being clicked

when i click the region it continually draws instead of when im holding the mouse. also ill figure out how to toggle the pencil when clicked later on. i am very new. ive tried some stuff with mouseclicked and mousebutton == left but i cant get it to work.
thanks

}
void mousePressed() {
  if (mouseX > 772 && mouseX < 864 && mouseY > 1 && mouseY < 74) {
    drawPencil = true;
  }

      
  }
  {
    if (drawPencil) {
       stroke(255);
    line(mouseX, mouseY, pmouseX, pmouseY);

Continued elsewhere

Chrisir