Sorry, this problem may be a little stupid. I can’t find very detailed steps on the Internet. I tried a code, but I don’t know why it doesn’t work. Please help me and tell me other methods or my coding errors.
Your code runs ok on my Mac, as is, after changing the curly quotes which apparently become altered with a copy/paste to the editor. The saved .png file is in the sketch folder. An alternate method would be to place if (keyPressed) {…} inside of draw() function. See https://processing.org/reference/key.html.