Run Trainspotter, click “Edit”->”Preferences”
Click the “Key detection” node on the left hand side:

Click “Get LAME here”
This brings up a browser and takes you to the rarewares site.
Note that as it says on the site “… visitors should be aware that download and usage of some binaries (namely, MP3 encoders and AAC encoders/decoders) may be forbidden due to patent legislation in their Countries. Consult your Country's software patent laws for more details.”
If you’re not going to be breaking any laws in your country, click the “download” link as shown below:

Extract the zip file to c:\program files\lame\

Go back to Trainspotter and browse to the lame.exe or type in c:\Program Files\lame\lame.exe in the Path to LAME MP3 encoder preference:

Next click “Get FLAC here”

Click the “FLAC for Windows (command line tools…)” link

Open up the flac-1.2.1-win folder and click flac-1.2.1b.exe
Run the program when it downloads
Install FLAC, accepting the defaults, it should install in to C:\Program Files\FLAC\, or similar
Go back to Trainspotter and enter C:\Program Files\FLAC\flac.exe in the “Path to FLAC encoder” preference:

Click “Apply”
Click “OK”
Click “Tools”->”Detect keys…”
You are now ready to start key detection.