function Press(){
document.querySelector("body").addEventListener("keyup", event => {
if(event.key !== "Shift") return;
document.getElementById("myElement").click();
event.preventDefault();
});
}
I set keyup for press Shift 1 time. How can I set it for 3 fast times? So that after Shift Shift Shift an event (document.getElementById("myElement").click()) is executed?
UPDATE:
this is working code made with @deceze help
function Press(){
document.addEventListener("keyup", event => {
if(event.key !== "Shift") return;
shift_pressed = typeof shift_pressed !== 'undefined' ? shift_pressed : 0;
shift_pressed++;
setTimeout(() => {
shift_pressed= shift_pressed-1 >= 0 ? shift_pressed-1 : 0;
}, 1000);
if (shift_pressed===3){
document.getElementById("myElement").click();
shift_pressed=0;
}
event.preventDefault();
});
}
thanks everyone for the help
2
Answers
That should trigger the click on every third press of the Shift key
Just create
setTimeout
for clearing counter of clicking Shift and defineclearTimeout
clear the timeout for every single click.