For example ctrl + Z + F7
In a particular component, you need to catch the fact of pressing such a combination.
For example ctrl + Z + F7
In a particular component, you need to catch the fact of pressing such a combination.
Something like this. Posted on the knee. I donβt think that itβs better than the options that libraries can offer, but it will help you to understand how the combination catching under the hood works)) You can delete the lines with comment //ΠΌΡΡΠΎΡ .
let catchCombination = (() => { let combination = []; window.addEventListener("keyup", () => { combination = []; document.getElementById("clicked").innerHTML = ""; //ΠΌΡΡΠΎΡ }); return (e, userCombination) => { combination.push(e.code); document.getElementById("clicked").innerHTML += "ΠΠ°ΠΆΠ°ΡΡ " + combination.join("+") + "<br>"; //ΠΌΡΡΠΎΡ if (combination.join("+").toLowerCase() === userCombination.toLowerCase()) { document.body.innerHTML += "<span style='color:green'>ΠΠΎΠΌΠ±ΠΈΠ½Π°ΡΠΈΡ ΠΏΠΎΠΉΠΌΠ°Π½Π°!<span><br>"; //ΡΡΡ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±ΡΡΡ ΡΠ²ΠΎΠΉ ΠΊΠΎΠ΄ } } })(); window.addEventListener("keydown", e => catchCombination(e, "ControlLeft+KeyZ+f7")); ΠΠ°ΠΆΠΌΠΈ Π² ΡΡΠΎ ΠΎΠΊΠ½ΠΎ, Π° ΠΏΠΎΡΠΎΠΌ Π·Π°ΠΆΠΌΠΈ control + z +f7!<br> <div id="clicked"></div> In the event object of the onkeyup (e) handler, there is the e.ctrlKey, e.metaKey, e.shiftKey property. Those. It is easy to track the combination of two keys, one of which is ctrl, alt, shift. I can not imagine the option where you need to hold down three keys in order to trigger something.
Source: https://ru.stackoverflow.com/questions/934792/
All Articles