My wireless Apple keyboard had the corroded battery problem. I read through the prior helpful comments but I’ve a slightly different suggestion that worked for me.
After unscrewing the cap to the battery tube, I applied white vinegar with a Q-tip to the end of the first corroded battery and let the keyboard sit for 15 minutes or so. Per a previous suggestion, I was planning to drill a hole in the battery, insert a long screw, and try to pull the battery out. I fixed a bit in my drill press, and propped the keyboard up vertically on the drill press table. But when I lowered the bit to drill a hole, the pressure of the bit against the battery loosened the battery without even drilling. I could see the battery move slightly in the tube. When the battery moved, I decided to see if it would come out without more work.
I knocked the keyboard gently on a table, and the first battery came out far enough that I could remove it with pliers. The remaining two dropped out easily. It appeared, luckily, that only the first battery was corroded. I took Q-tips and vinegar and cleaned out the battery tube.
Then I inserted new batteries. No luck; the keyboard wouldn’t turn on. I looked into the battery tube and found that some corrosive crud had lodged on the positive contact at the other end. Cleaning this off with a wood dowel solved the problem.
The essential element was applying pressure on the batteries. Not much pressure was required, perhaps because only one battery was corroded, and the batteries need only move enough to loosen the corrosion. But this method eliminates banging the keyboard hard or removing the circuit board. Other methods of applying pressure might work equally well.