When you’re editing text in Adobe InDesign, switching to a different tool cannot be done simply by hitting the keyboard shortcut for that tool because you’ll end up typing that letter in the text frame.
Instead, to switch to another tool, Command + Click on the text frame or hit Command + Shift + A to exit text editing mode. You can then hit the appropriate letter to switch tools, such as P for the Pen tool, or M for the Rectangle tool.