How to choose an external powersource with electronic logic
Overview
What you are describing is called a an SPS (standby power source). You may be familiar with its counter-part the UPS (uninterruptible power source). Actually, what most companies sell as &quot;UPS&quot; for personal computers are actually SPS.
The core difference being that an SPS switches to a second power source if the primary is interrupted and the UPS keeps both available at all times so there is no switching delay.
The physics
That said, WHY can't you use two batteries in your system? I think that is the bigger issue. A battery (like any source) provides two quantities: force (voltage) and flow (current) -- that's a simplification. It's like a water tank on a hill. The weight of the water (its mass in concert with gravity) creates pressure (force) on the downstream valves. When you open the faucet, the water (energy quantums) flow out (energy equating to the ability to do work).
A possible solution
Sorry for all the physics, here's why that matters: The source (batteries) determine the force (voltage), but the load (thing you are trying to power) determines how much energy it needs (how much current flows).
With your batteries, any system that can tolerate one battery, can tolerate two so long as the voltage of the battery system remains the same. Connecting the batteries in parallel achieves this. If you use two batteries of the same chemistry, size, and age, simply connecting them in parallel will almost double the run-time compared to just a single one and you will not have to deal with any switching.
If you need to change the batteries without interrupting the system, just change them one at a time before the voltage of the parallel combination drops too low (say about 1.38V for EE91 alkaline chemistries). The load will transfer to the remaining battery once the second battery is removed. However, if you wait too long, the remaining single battery may not be able to support the system on its own in its sufficiently weakened state.
The &quot;simplest&quot; SPS
If you Google for &quot;USB Relay Board&quot; you will find a tremendous number of vendors selling off-the-shelf modules that you can program over a USB serial link and will open and close one of many relays on command. You can use this implement your desired battery switching scheme (still not sure why you need to do this).

As I depicted, you bus the connection to the positive battery terminal of your key to all of one terminal of the relays. You connect each battery to a relay (at the other terminal of the relay) and you bus all of the battery negative terminals back to the negative terminal of your key.
You can add as many USB relay modules as you need. Just be careful with your software so that you implement break-before-make sequencing (disconnect, open, all of the relays before connecting the one you want to use).
Welcome
I hope that covers the basics. If you have any follow-up questions, please ask and I'll elaborate. Cheers!