When you figure out a key that a song is written in. Will the entire song use the chords in that key? With maybe an accidental?? I've tried several different methods.
While you will find that in most cases, the chords used in a song will all be diatonic chords - meaning chords comprised of notes from within the root key of the song - there are often exceptions - many of which occur commonly enough to have names associated with them.
For example the "Neapolitan Chord" is used in many types of music from Classical to Rock and Pop. From the Wikipedia article on Neapolitan chord:
In music theory, a Neapolitan chord (or simply a "Neapolitan") is a major chord built on the lowered second (supertonic) scale degree. Also, in Schenkerian analysis, it is known as Phrygian II,1 since in minor scales the chord is built on the notes of the corresponding Phrygian mode.
In tonal harmony, the function of the Neapolitan chord is to prepare the dominant, substituting for the IV or ii (particularly ii6) chord. For example, it often precedes an authentic cadence, where it functions as a subdominant (IV). In such circumstances, the Neapolitan sixth is a chromatic alteration of the subdominant, and it has an immediately recognizable and poignant sound.
There are several fantastic explanations of the Neapolitan chord in this answer on Stack Exchange - What is a Neapolitan Sixth
Another common use of a particular chord not found in the root key is known as a "Picardy third".
From the Wikipedia article on Picardy third :
refers to the use of a major chord of the tonic at the end of a musical section that is either modal or in a minor key. This is achieved by raising the third of the expected minor triad by a semitone to create a major triad, as a form of resolution.3 For example, instead of a cadence ending on an A minor chord containing the notes A, C, and E, a tierce de Picardie ending would consist of an A major chord containing the notes A, C♯, and E. Note that the minor third between the A and C of the A minor chord has become a major third in the tierce de Picardie chord.
Another common practice is the use of what is known as a "borrowed chord" or "modal interchange" which both refer to the use of a chord "borrowed" from a parallel key. By "parallel key" I mean a key with the same root or tonic as the primary key, but in a different mode. A simple example is that in the key of C - one parallel key would be C natural minor. While the "relative minor" of the key of C is A minor and contains the same notes as the key of C major - the parallel minor of C major is C minor which has different notes and therefore different chords (but still revolves around the same tonic - "C").
The most common use of borrowed chords is to use chords from the parallel natural minor in a major key.
From the Wikipedia article on Borrowed chord :
A borrowed chord (also called mode mixture and1 modal interchange) is a chord borrowed from the parallel key (minor or major scale with the same tonic). Borrowed chords are typically used as "color chords", providing variety through contrasting scale forms, major and the three forms of minor.3 Similarly, chords may be borrowed from the parallel modes, the various modes beginning on the same tonic as a scale, for example Dorian with D major.1
And sometimes chords are "altered" by using chromatic notes (from outside the key) as leading tones to emphasize the neighboring diatonic tone. Using a non diatonic note creates more tension and thus a more powerful resolution when the chromatic notes lead back to a diatonic chord.
Much of what I know about the use of chords outside the primary key came from right here on Stack Exchange - Music Practice and Theory. Below is a link to some questions I posted that were similar to yours. The answers to these two questions may give you more insight into how and why certain chords from outside the primary key can be very effective.
There are a number of different things that the word 'key' is used to describe, which can be a little confusing.
When people talk about the notes in a major key, or chords in a major key, they tend to be talking about the set of notes strictly belonging to the diatonic major scale for that key (or the chords constructed from them), which corresponds to the set of unaltered natural notes for that same key signature.
When people talk about the notes in a minor key, the idea is similar, except that there is some 'wiggle room' allowing the 6th or 7th degrees to be raised relative to their natural pitch according to the key signature (most often expressed as the existence of 'forms' of the minor scale - natural, harmonic, and melodic). So when people talk about notes in a minor key, they may be talking about this wider set of notes, rather than just the notes in the natural (diatonic) minor scale.
When people talk about the key that a song or other piece of music is in, this often doesn't mean that the song only uses notes in the key. Rather, it often means that the notes in that key are the place that the song 'comes home' to, or that they are the primary set of notes used in a song. In these cases, the piece may stick strictly to the notes in the key, or it may stick mostly to the notes in a key, but use a note or two (or chord or two) borrowed from another key. Rockin Cowboy's answer has a lot of good examples of ways to use chords outside of the key.
Sometimes, a piece may modulate to another key that is identifiably different from the 'home' key, this points to another thing that can be described with the word 'key' - the key that a section of a piece is in (even if the piece as a whole is said to be in a different key). This may happen more than once, taking the piece on a journey through a number of keys (and often, but not always, returning to the original home key). A simpler kind of key change is often found in pop music, moving the piece up a semitone or whole tone for dramatic effect.
There is another sense in which a song can be said to be in a key, which is when that key is a useful approximation of the tonality of a piece. Many rock songs, for example, are a hybrid of mixolydian and blues tonality, and don't really adhere fully to the major scale and major tonality. However, these songs are often said to be in a major key if, the tonic chord in the piece is major.
This leads on to an answer to your question - how to figure out the key that a song is in. For a simple song, that's usually quite straightforward:
Listen for the chord (and root note of that chord) that the song 'calls home'. This doesn't mean necessarily the last (or first) chord, but the chord that the song revolves around. Often this is the first chord of the verse, or the last (and/or first) chord of the chorus; Often it's also the most common chord in the piece. With practice it's usually easy to recognise it.
Work out if that home chord is major or minor.
If the piece comes home to the note A and the A minor chord, then it's probably safe to say it's in A minor. Likewise, if it comes home to D and the D major chord, it's probably in D major. But as we've said already, this doesn't mean that it won't use notes and chords outside the natural set for the key.
Not necessarily. While the key gives you a good idea of what harmony to expect, not all the chords need to be in that key. Chords can be borrowed from other modes/keys, chords can created by chromatically altering tones, and you may even modulate or change keys mid song.
A simple example is in the key of C, you may encounter a progression
C - D - G - C. While the D major chord, which consist of the notes D, F♯, and A, is not part of the key of C we are altering the F♯ it to tonicize the G major. This kind of chord is known as a secondary dominant and can be seen as borrowed from the key it is tonicizing which in this case is G major.
Quick answer, no. It's wide open. I could offer a huge list of simple pop/rock songs that use more than diatonic chords, way beyond "maybe an accidental". Look at real songs. When a "foreign" chord appears, you can jump through hoops attempting to justify it as "borrowed" from the second cousin twice removed of the relative minor of the submediant - or you can just add it to your list of possibilities. Actually, take a middle path. Look for the actual link. A "way out" chord will often have a note in common with the preceding chord, so you can think of it as giving a repeated melody note a different harmonic flavour. Or it may have been reached by parallel movement or "planing" - guitar players are fond of doing this as it's easy to achieve by shifting a full barre shape up or down the fingerboard.
If you want to see most of the chords that you can use in any key, there's nothing better than this map
(I took the snapshots from the Mapping Tonal Harmony Pro app)
This is to some extent a historical question. In general, songs in the Western tradition will tend to stick more to the chords within the key- that is, no accidentals- the older and folkier they are. More modern songs start using more accidentals and thus more chords out of their keys. Perhaps the first was the major dominant chord in a minor key- say, E major in A minor, requiring a G#. Others followed, and some modern songs use pretty much all twelve tones and thus many chords outside their key.
So the answer is not simple, but rather a study of music history.
A key is the chord that your ear will hear as the 'home', or the chord that will seem to resolve all the tension created in the other chords. The chords that will still keep the 'home' chord the same are (not including dim or +):
I, ii, II, ii, III, iii, IV, V, vi, VI, and sometimes iv, vii.
There are some exceptions (looking at you major 7th, that major chord a half step above the fifth, and the major chord a full step down from the home chord (don't know how to represent them in roman numerals)) but they are rare, at least in pop music.
P.S. Don't ever let anyone tell you that the diminished 7th is a viable chord in a key, no song ever uses it because it sounds gawd awful. Also, it is very common for a song to change keys and take on the chords from the new key.