I have a wireless keyboard that I would like to power through a USB cord, I am not a fan of wireless, especially due to the battery use. I would however like to have the possibility of having the voice to use the batteries whenever I please. Now the keyboard is powered by 4AA batteries, judging by how they are positioned I am guessing placed in parallel 2x2. In order to power it I am planning to attach a micro-usb connector, and a voltage regulator to drop the voltage to 3.3V. I looked a bit around on how to create a switch which would disconnect the batteries whenever the USB is attached, and found several posts like this one: Automatically switching from battery to DC wall adapter on insertion however I am still confused as to what I should do. I tried simulating a circuit using a p-MOSFET:
simulate this circuit – Schematic created using CircuitLab
While it appears to work when simulating it on http://www.falstad.com/circuit/, there is some back-current towards the battery. Also This seems like a bit too simple compared to other circuits I've seen around. Is this really a solution? I know there are some IC that can do power management, but they are a bit expensive for my taste, if I have to spend 10$ on it then I'd rather just cut off the battery part and go with the cabled solution. Thank you