Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

473
Vistas
Angular - How to trigger keyboard events on button click?

I have provided two separates button for Ctrl+z and Ctrl+y. I want the Ctrl+z and Ctrl+y functionality to be performed on the click of a button. Here is my function.

undoText(event:MouseEvent){
    var element =   document.getElementById("undoBt")
     if(element){
        element.dispatchEvent(new KeyboardEvent('keydown',{composed: true, bubbles:true, cancelable:true, code:"ControlLeft", ctrlKey:true, key:'Control',keyCode:17, location:1}));
        element.dispatchEvent(new KeyboardEvent('keydown',{bubbles:true,   cancelable:true, code:"KeyZ", composed:true, ctrlKey:true, key:'z', keyCode: 90}));
       }

  }

Here is my html.

<mat-icon matTooltip="Undo"  (click)="undoText($event)" *ngIf="svgInit" id="btn1" class="undo" svgIcon="undo" aria-hidden="false" aria-label="undo">
        </mat-icon>

To achieve this, I am trying to trigger Ctrl+z and Ctrl+y on button click but they are not getting triggered and I'm not able to set isTrusted property true.

What is wrong with the code?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

(keyup.enter)="keyUpFunction($event)"

Where keyUpFunction($event) is your function.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda