Keep humming the melody and try to identify the note which brings it to a pleasing conclusion.
Determining the key of a song is the first step towards finding the chords for playing with the song. In most cases, the key is the first note of the song, or more probably, the last and final note of the song. It is also the note which is repeated several times in the song. If you can play this note in your musical instrument, then you can easily determine the key.
Another method of determining the key is as follows.
First listen to the song a couple of times, or until you have memorized the melody.
Next pick up the guitar, or the piano (you don’t have to pick up the piano). Hum the melody gently and as you hum try to bring the melody to a satisfying conclusion. Every song has an ending. It is like a curtain-fall. It tells you that it is over and it fills you with satisfaction. It does not leave you hanging in the air (although there are some rare songs which end with an inconclusive note). So, keep humming the melody and try to identify the note which brings it to a pleasing conclusion. You might fail the first time, but with practice you will be able to find the key note quickly.
Now locate this key note on the 3rd string (G string) of the guitar, or play the keys of the piano and find the note. After you are confident that you have found the right note, play the major chord related to the note in the same pattern you play the A major or B major chord (on guitar). Does it match? If you feel like it does not suit the melody, play the minor chord in the same pattern you play the A minor or B minor chord (on guitar). If you listen carefully, you know which chord matches. Consequently, you will understand whether it is a major key or a minor key.
Once you have determined the key, start adding chords from the related chord family.