The key code comes printed with the game itself — look on the disc case, usually on a sticker on the back or on the manual insert. It follows a straightforward pattern of number groups separated by hyphens, for example: 0123-4567-8910.
If the case has been thrown away and you can't find the code, there's no way to recover it, and you'll need a new copy of the game. It's a good argument for photographing your keys and storing the pictures somewhere safe the moment you open a new purchase.