code: def prompt_toolkit_key_to_vt100_key(key, application_mode=False):
      
      application_mode_keys = {
          Keys.Up: '\x1bOA',
          Keys.Left: '\x1bOD',
          Keys.Right: '\x1bOC',
          Keys.Down: '\x1bOB',
      }
  
      if key == Keys.ControlJ:
          # Required for redis-cli. This can be removed when prompt_toolkit stops
          # replacing \r by \n.
          return '\r'
  
      if key == '\n':
          return '\r'
  
      elif application_mode and key in application_mode_keys:
          return application_mode_keys.get(key)
      else:
          return _PROMPT_TOOLKIT_KEY_TO_VT100.get(key, key)
docs: Turn a prompt toolkit key. (E.g Keys.ControlB) into a Vt100 key sequence.
      (E.g. \x1b[A.)