L'event "keydown" s'active plusieurs fois
Résolu/Fermé
Hibou-Propulseur
Messages postés
3
Date d'inscription
lundi 26 juillet 2021
Statut
Membre
Dernière intervention
22 août 2021
-
Modifié le 26 juil. 2021 à 18:25
kaneagle Messages postés 85680 Date d'inscription mercredi 27 mai 2009 Statut Modérateur Dernière intervention 17 février 2025 - 22 août 2021 à 14:25
kaneagle Messages postés 85680 Date d'inscription mercredi 27 mai 2009 Statut Modérateur Dernière intervention 17 février 2025 - 22 août 2021 à 14:25
2 réponses
Hibou-Propulseur
Messages postés
3
Date d'inscription
lundi 26 juillet 2021
Statut
Membre
Dernière intervention
22 août 2021
Modifié le 26 juil. 2021 à 18:34
Modifié le 26 juil. 2021 à 18:34
Ok j'ai trouvé une réponse... (https://javascript.info/keyboard-events)
Auto-repeat
If a key is being pressed for a long enough time, it starts to “auto-repeat”: the keydown triggers again and again, and then when it’s released we finally get keyup. So it’s kind of normal to have many keydown and a single keyup.
For events triggered by auto-repeat, the event object has event.repeat property set to true.
donc ça donne :
EDIT: Comment on fait pour clore ce sujet ?
Auto-repeat
If a key is being pressed for a long enough time, it starts to “auto-repeat”: the keydown triggers again and again, and then when it’s released we finally get keyup. So it’s kind of normal to have many keydown and a single keyup.
For events triggered by auto-repeat, the event object has event.repeat property set to true.
donc ça donne :
document.addEventListener("keydown", function(e) { console.log("keydown"); for(var k in dict) { if (e.keyCode == k) { if (e.repeat != true){// petite modif ici ! console.log("touche n°: "+k+" appuyée"); function modif(){ dict[k](); refresh(); } modif(); dictIntervalles[k] = setInterval(modif,1000/nbDePasParSec); } } } });
EDIT: Comment on fait pour clore ce sujet ?
kaneagle
Messages postés
85680
Date d'inscription
mercredi 27 mai 2009
Statut
Modérateur
Dernière intervention
17 février 2025
14 385
22 août 2021 à 14:25
22 août 2021 à 14:25
Bonjour,
Regarde ceci -->> Marquer un fil de discussion comme étant résolu
Comment on fait pour clore ce sujet ?
Regarde ceci -->> Marquer un fil de discussion comme étant résolu