Search code examples
javascriptinputlowercase

Changing keyDown presses to lower case


I am trying to compare 2 characters (or key codes) to check if the letter on the screen is the same as the pressed character.

Sadly, all the keyDown results are in upper-case, and I would like to know if there's a different way that gets input as lower-case instead of manually changing all the input.

Here's my code:

document.onkeydown = function keyDown(e) {
  if (!e) e = window.event;

  if (e.keyCode == currentCharacter.charCodeAt(0)) {
      // Input matches the current character.
  } else {
      // Input does not match the current character.
  }
}

In this example, e.keyCode always returns the keycode for an upper-case version of the character I pressed.


Solution

  • According to this,

    Using keyPress event rather than keyDown might be the answer.