Created
May 17, 2024 01:33
-
-
Save sostenesapollo/45f1f68ac8f25fb6a1721d36564115a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pressRightArrow() { | |
// Identifica o elemento que deve receber o evento de tecla | |
const element = document.activeElement || document.body; | |
// Cria o evento de pressionamento da tecla (keydown) | |
const keydownEvent = new KeyboardEvent('keydown', { | |
key: 'ArrowRight', | |
code: 'ArrowRight', | |
keyCode: 39, | |
which: 39, | |
bubbles: true, | |
cancelable: true | |
}); | |
// Cria o evento de liberação da tecla (keyup) | |
const keyupEvent = new KeyboardEvent('keyup', { | |
key: 'ArrowRight', | |
code: 'ArrowRight', | |
keyCode: 39, | |
which: 39, | |
bubbles: true, | |
cancelable: true | |
}); | |
// Despacha o evento de pressionamento da tecla | |
element.dispatchEvent(keydownEvent); | |
// Despacha o evento de liberação da tecla | |
element.dispatchEvent(keyupEvent); | |
} | |
// Define um intervalo que chama a função pressRightArrow a cada 1 segundo (1000 milissegundos) | |
setInterval(pressRightArrow, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment