If you are being directed to enter a recovery key, your Apple ID uses Two-Step authentication, and not Two-Factor which doesn't require a recovery key.
If you lose your recovery key, you can create another one if you have a trusted device that is already signed into the account. Without access to another trusted device, and without knowing your recovery key, you will be unable to sign in and generate a replacement key. See the FAQs at https://support.apple.com/en-us/HT204152.
If you use your Apple ID to log into your computer (as it sounds like the OP does), in some cases you can remove the link between the local macOS account and the Apple ID so that you can sign into the Mac and regain access to all of your data. If you have a second Admin account, or if you are able to force the system to create a new one, then you will be able to manipulate your account to disconnect from Apple ID, and potentially create a new one, however your access to the existing Apple ID is lost if you can't provide the recovery key, and any data associated with the account will also remain unavailable. This is a particular problem if you have been using iCloud Drive to store your Desktop and Documents.
In this case, you will be better off contacting your local AppleCare support line to assist you to regain access to your system, as they are likely to have either tools or process which can assist you in this case.