In Ableton Live, many shortcut keys work in two modes depending on how you press them. A quick tap toggles the function on or off, while holding the key keeps it active only as long as you hold it. This applies to B for the pencil tool, S for solo, and Z for zoom, among others.
When the computer MIDI keyboard is active, holding Shift temporarily disables it so your shortcut keys work as expected, letting you switch tools mid-session without turning the MIDI keyboard off entirely.