The key signature at the start of a piece of music represents one major key, and one minor key.
In sharp major keys, the sharp written furthest right in the key signature is the leading note, and the keynote or tonic is one semitone higher.
In flat major keys, the penultimate flat in the key signature is the tonic (keynote).
The relative minor key is a third lower. The 7th degree of the scale is often raised with an accidental in the music itself. The 6th degree is also sometimes lowered, to avoid an augmented 2nd.
To work out whether the piece of music is major or minor, look at whether any accidentals from the minor scale have been added to the music. You can also look at any patterns of arpeggios or broken chords, as these are more likely to outline the tonic and/or dominant chord in the correct key.
Here’s an example. The penultimate flat in the key signature is Ab, and F is a third lower, so the two possible keys are Ab major or F minor. In the scale of F minor harmonic, we find E natural as an added accidental.
This piece uses the note E natural, and also outlines a broken chord of F minor in bar 1. The key is F minor.
Here’s a melody in the tenor clef. The process for working out the key is the same. There are three sharps, and the last one is G#. This means the major key will be A major, and the minor key will be F# minor. There are no additional sharps written in the music, and the first three notes outline a triad of A major, so the key is A major.