I've been looking for a way to reproduce this since about the times of Stata 10, and finally today found a reliable scenario:
  1. make sure the output window is full of content so that the vertical scroll bar appears;
  2. in the command line start typing a command, make sure there is a word followed by a space
  3. left click the output window
  4. scroll the output window with a mouse wheel
  5. press ESC
Expected: the command window becomes active and the keyboard cursor is restored at the end of the line (or last active position)
Actual: the ESC character is pasted into the input line. In older Statas it was shown as ^Z, in Unicode Statas it is shown as ESC:

Array

Occasionally other characters may appear, but ESC is the most frequent one.

Array

The above scenario occurs pretty frequently when you start typing the command and realize you need to find e.g. the exact variable name from the output content which is already off the screen. In this case the behavior of the keyboard is rather irksome.

Observed in Stata 15.1MP for Windows. and in earlier versions dating back a few generations.