Is there a place where emacs stores commands the user has recently executed, in particular via keyboard shortcuts, and if not, would it be possible to tell it to store them somewhere? I sometimes type the wrong keyboard shortcut by accident and I don't know what it is that I did. I undo it, but I tend to repeat these accidental shortcuts every once in a while, and I have no idea how to find out what exactly I pressed or what command I ran.
I know how to determine what command is bound to a key. My issue is that I know neither the command nor the keys I pressed, only what effect they had and the fact that I recently did it.
last-command
to something special, for the most part you can just check the value of that variable to see the most recent last command.