While those with 'perfect pitch'* can presumably call out a note value (or closest note value, since Zeno's paradox suggests it's highly unlikely to end up on the 'exact' value [and referenced to what
atomic clock, anhyhow?
]), many folks with an even lightly trained ear can pick out notes on an instrument against a piece of music and, by listening for the note's harmonicity with the music or lack thereof, tell if that note is in the music's key scale. Do that enough and you can figure out the notes in the whole scale a note at a time and then figure the key from there.
That said, much modern music has modulations within it where the mode and/or scale changes in the course of the song, so one has to remain aware of that.
(When I was first trying to learn how to play lead, I had no idea that songs changed mode... I basically figured it out by trial and error. Of course, there are some soloists who simply go for the 'lowest common denominator' -- for instance, restricting themselves to a pentatonic scale when playing blues because they can't be bothered with keeping track of modal shifts.)
really is -- I've asked questions of a number of folks who claim it and often received conflicting answers when I ask them how they deal with nonstandard tuning where A is not 440 Hz but some other value -- I've also asked those claiming perfect pitch for their insight into Equal Temperament vs Just/mathematically correct intervals and got either confusion or conflicting answers. FWIW, I certainly don't have 'perfect pitch' in the sense that I can call out note values just listening without reference. (And, in fact, when I started, I couldn't even tell which of two close tones was the higher.) But I did
'memorize' the pitch of my old A440 tuning fork with enough accuracy that I could pretty much get the A string within a few cents. (And screwed that when I started dropping all my guitars a half step.