Function addKeyListener

  • Add a listener to the DOM for the specified key.

    Parameters

    • key: string

      The key (event.key) to listen for.

    • handler: ((event) => void)

      The callback to trigger when the key is detected.

        • (event): void
        • Parameters

          • event: KeyboardEvent

          Returns void

    Returns (() => void)

    A cleanup function that will unbind the listener. This should be called to prevent memory leaks.

      • (): void
      • Returns void