Check out example codes for "how to block a rectangle from going off screen p5". It will help you in understanding the concepts better.

Code Example 1

if ((keyIsPressed == true) && ((key == 'a') || (key == 'A'))) {

Learn ReactJs, React Native from akashmittal.com