I know there is a way that Maya checks for previous keyframes, because you can actually click on a button next to the play buttons that will jump to the next or previous keyframes.
Turning "echo all commands" on, in the script editor gives me:
currentTime -edit `findKeyframe -timeSlider -which previous`;
when I click the go to previous key button . . .
That is probably a good hint on the direction you would want to go when writing the code to find if there is a previous keyframe.
"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche