Keep humming the melody and try to identify the note which brings it to a pleasing conclusion.
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 try to bring it to a satisfying conclusion. Every song has an ending. It is like a curtain-fall. It tells you that it is over and it satisfies you. It does not leave you hanging in the air (although there are some rare songs which end with an inconclusive note). Keep humming the melody and try to identify the note which brings it to a pleasing conclusion.
Now locate this note on the 3rd string (G string) of the guitar. 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. 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. 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.