user15350339
user15350339

Reputation: 40

Keyboard Not detecting input

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

Answers (2)

Gabriel
Gabriel

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

Dequog
Dequog

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

Related Questions