Reputation: 40
Hello I am making a website, and am trying to make a keyboard shortcut, but it can't detect the key.
Here is my code:
document.addEventListener("keydown", (e) => {
if (e.key === "l" && e.ctrlKey && e.shiftKey) {
console.log("Please Work I Beg Of You");
}
});
Upvotes: 1
Views: 35
Reputation: 690
you can check keyCode instead
document.addEventListener("keydown", (e) => {
if (e.keyCode === 76 && e.ctrlKey && e.shiftKey) console.log("Please Work I Beg Of You");
});
Upvotes: 1
Reputation: 124
No more information needed. The computer will read the L key as being capital because you pressed shift, so just change it to "L" (I'm not sure if this'll work, but might also be able to do e.key.toLowerCase()
). Let me know if this works
Upvotes: 2