Escaping a webcam capture, is there an inbuilt function?

I’m using this in for my per_frame function with no success at all and am trying to check if there is something in-built?

if cv2.waitKey(33) == ord(‘a’):
print(“Exiting . . .”)
return True

Any help would be appreciated, cheers!