How do you work out the key of a song other than by ear 'just hearing' what key it's in?
Well unless you have the sheet music, you have to judge by ear, don't you? Unless you're asking what someone does to determing a song's key. This might not come out right, but the key of a song is that which all the notes play relative to.

E.g. the chord progression Dmaj-Emin-Gmaj--Bmin-F#min-Gmaj (give or take) in the chorus of Iris by Goo Goo Dolls, comprises of notes all to be found in the key of D major.
As the guys have said, if you've got sheet music or a chord chart, you can figure it out based on that. If not, you need to listen for the note which sounds most resolved when you land on it, that is your tonic.