class_docstr: :param recognize_paste: When True, try to discover paste actions and turn
      the event into a BracketedPaste.
docstr: For this `KEY_EVENT_RECORD`, return a list of `KeyPress` instances.
docstr_tok: ["For","this","`","KEY_EVENT_RECORD","`",",","return","a","list","of","`","KeyPress","`","instances","."]
code: def _event_to_key_presses(
      self, ev: KEY_EVENT_RECORD
  ) -> list[KeyPress]:
      """
      For this `KEY_EVENT_RECORD`, return a list of `KeyPress` instances.
      """
      assert isinstance(ev, KEY_EVENT_RECORD) and ev.KeyDown
  
      result: KeyPress | None = None
  
      control_key_state = ev.ControlKeyState
      u_char = ev.uChar.UnicodeChar
      # Use surrogatepass because u_char may be an unmatched surrogate
      ascii_char = u_char.encode("utf-8", "surrogatepass")
  
      # NOTE: We don't use `ev.uChar.AsciiChar`. That appears to be the
      # unicode code point truncated to 1 byte. See also:
      # https://github.com/ipython/ipython/issues/10004
      # https://github.com/jonathanslenders/python-prompt-toolkit/issues/389
  
      if u_char == "\x00":
          if ev.VirtualKeyCode in self.keycodes:
              result = KeyPress(self.keycodes[ev.VirtualKeyCode], "")
      else:
          if ascii_char in self.mappings:
              if self.mappings[ascii_char] == Keys.ControlJ:
                  u_char = "\n"  # Windows sends \n, turn into \r for unix compatibility.
              result = KeyPress(self.mappings[ascii_char], u_char)
          else:
              result = KeyPress(u_char, u_char)
  
      # First we handle Shift-Control-Arrow/Home/End (need to do this first)
      if (
          (
              control_key_state & self.LEFT_CTRL_PRESSED
              or control_key_state & self.RIGHT_CTRL_PRESSED
          )
          and control_key_state & self.SHIFT_PRESSED
          and result
      ):
          mapping: dict[str, str] = {
              Keys.Left: Keys.ControlShiftLeft,
              Keys.Right: Keys.ControlShiftRight,
              Keys.Up: Keys.ControlShiftUp,
              Keys.Down: Keys.ControlShiftDown,
              Keys.Home: Keys.ControlShiftHome,
              Keys.End: Keys.ControlShiftEnd,
              Keys.Insert: Keys.ControlShiftInsert,
              Keys.PageUp: Keys.ControlShiftPageUp,
              Keys.PageDown: Keys.ControlShiftPageDown,
          }
          result.key = mapping.get(result.key, result.key)
  
      # Correctly handle Control-Arrow/Home/End and Control-Insert/Delete keys.
      if (
          control_key_state & self.LEFT_CTRL_PRESSED
          or control_key_state & self.RIGHT_CTRL_PRESSED
      ) and result:
          mapping = {
              Keys.Left: Keys.ControlLeft,
              Keys.Right: Keys.ControlRight,
              Keys.Up: Keys.ControlUp,
              Keys.Down: Keys.ControlDown,
              Keys.Home: Keys.ControlHome,
              Keys.End: Keys.ControlEnd,
              Keys.Insert: Keys.ControlInsert,
              Keys.Delete: Keys.ControlDelete,
              Keys.PageUp: Keys.ControlPageUp,
              Keys.PageDown: Keys.ControlPageDown,
          }
          result.key = mapping.get(result.key, result.key)
  
      # Turn 'Tab' into 'BackTab' when shift was pressed.
      # Also handle other shift-key combination
      if control_key_state & self.SHIFT_PRESSED and result:
          mapping = {
              Keys.Tab: Keys.BackTab,
              Keys.Left: Keys.ShiftLeft,
              Keys.Right: Keys.ShiftRight,
              Keys.Up: Keys.ShiftUp,
              Keys.Down: Keys.ShiftDown,
              Keys.Home: Keys.ShiftHome,
              Keys.End: Keys.ShiftEnd,
              Keys.Insert: Keys.ShiftInsert,
              Keys.Delete: Keys.ShiftDelete,
              Keys.PageUp: Keys.ShiftPageUp,
              Keys.PageDown: Keys.ShiftPageDown,
          }
          result.key = mapping.get(result.key, result.key)
  
      # Turn 'Space' into 'ControlSpace' when control was pressed.
      if (
          (
              control_key_state & self.LEFT_CTRL_PRESSED
              or control_key_state & self.RIGHT_CTRL_PRESSED
          )
          and result
          and result.data == " "
      ):
          result = KeyPress(Keys.ControlSpace, " ")
  
      # Turn Control-Enter into META-Enter. (On a vt100 terminal, we cannot
      # detect this combination. But it's really practical on Windows.)
      if (
          (
              control_key_state & self.LEFT_CTRL_PRESSED
              or control_key_state & self.RIGHT_CTRL_PRESSED
          )
          and result
          and result.key == Keys.ControlJ
      ):
          return [KeyPress(Keys.Escape, ""), result]
  
      # Return result. If alt was pressed, prefix the result with an
      # 'Escape' key, just like unix VT100 terminals do.
  
      # NOTE: Only replace the left alt with escape. The right alt key often
      #       acts as altgr and is used in many non US keyboard layouts for
      #       typing some special characters, like a backslash. We don't want
      #       all backslashes to be prefixed with escape. (Esc-\ has a
      #       meaning in E-macs, for instance.)
      if result:
          meta_pressed = control_key_state & self.LEFT_ALT_PRESSED
  
          if meta_pressed:
              return [KeyPress(Keys.Escape, ""), result]
          else:
              return [result]
  
      else:
          return []
  
imports: from __future__ import annotations
  import os
  import sys
  from abc import abstractmethod
  from asyncio import get_running_loop
  from contextlib import contextmanager
  from ..utils import SPHINX_AUTODOC_RUNNING
  from ctypes import Array, pointer
  from ctypes.wintypes import DWORD, HANDLE
  from typing import Callable, ContextManager, Iterable, Iterator, TextIO
  from prompt_toolkit.eventloop import run_in_executor_with_context
  from prompt_toolkit.eventloop.win32 import create_win32_event, wait_for_handles
  from prompt_toolkit.key_binding.key_processor import KeyPress
  from prompt_toolkit.keys import Keys
  from prompt_toolkit.mouse_events import MouseButton, MouseEventType
  from prompt_toolkit.win32_types import INPUT_RECORD, KEY_EVENT_RECORD, MOUSE_EVENT_RECORD, STD_INPUT_HANDLE, EventTypes
  from .ansi_escape_sequences import REVERSE_ANSI_SEQUENCES
  from .base import Input
label_desc: Use image node_id 8 for calling the ConsoleInputReader obj's underlying member method code with example usage: obj._event_to_key_presses(ev) and returns: list, list, list, list