You don't need the key code, because BMW doesn't work that way, like some other brands.
In order to get a Key work, by my experience, is better to order one from BMW. You just have to give them the VIN number. Then put in the car and the Maxisys have a menu to enable/disable the key.
Automatically the CAS accepted the key, and you can star the engine and the remote work well to.
I know that Autel R&D is working in something, to be able to code used keys and other stuff. But this function is not be able so soon.