While the tool is selected, click onto the surface while holding the click drag on Z(blue) direction then release it, then press the left/right/up arrow on your keyboard and drag the the first line of your rectangle to that locked direction then draw the other side the same way.
Yet, you can do this with the pencil tool in the same manner.
Click to play !