Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

472
Visualizações
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 Respostas
Responde à pergunta

0

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

Where keyUpFunction($event) is your function.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda