Breaking down your code example (Explanations are under the line of code.)
import cv2
imports openCV for usage
camera = cv2.VideoCapture(0)
creates an object called camera, of type openCV video capture, using the first camera in the list of cameras connected to the computer.
for i in range(10):
tells the program to loop the following indented code 10 times
return_value, image = camera.read()
read values from the camera object, using it's read method. it resonds with 2 values save the 2 data values into two temporary variables called "return_value" and "image"
cv2.imwrite('opencv'+str(i)+'.png', image)
use the openCV method imwrite (that writes an image to a disk) and write an image using the data in the temporary data variable
fewer indents means that the loop has now ended...
del(camera)
deletes the camrea object, we no longer needs it.
you can what you request in many ways, one could be to replace the for loop with a while loop, (running forever, instead of 10 times), and then wait for a keypress (like answered by danidee while I was typing)
or create a much more evil service that hides in the background and captures an image everytime someone presses the keyboard...