You plan ahead. I made duplicate keys to my condo and my car and gave them to a couple friends who can be relied on.
In a system with electronic lock you could have unique factory key stored at the manufacturer, and recovered for a $30 fee upon inspection of id/receipt/etc.