a pitcher has to commit to throwing with one arm or the other for each batter, they cannot switch during an at bat.
who has to commit to a side first, I am not sure, there must be a complicated rule for that.
there have been a few switch pitchers in baseball, but none with any real amount of success. one even had a special pitchers glove made that he could wear on either hand depending which arm he was pitching with.
a quick google on switch pitching yields this quick note:
hree switch pitchers played in the pre-1900 era, but the only contemporary major leaguer to do it was ex-Padre, officially listed as a righty, Greg Harris in 1995, when he was with the Expos. He pitched to one batter with his left hand and walked him. Harris always claimed ambidextriosity but was in the majors for many years before he actually got a chance to try. When he played for Boston, the manager wouldn't let him do it for some strange "purity of the game" reasons. Bert Campanaris pitched from both sides in the '60s in the A's farm system, and there are a couple of switchers in the minors today. Baseball rules say you can't change pitching hands in a single at-bat (that's a balk), just between batters.