1

I'm using the following code to detect a key being pressed:

$(document).keyup(function(event) { // the event variable contains the key pressed            
    if (event.which == x+65) { 
        alert(numToChar(x));
    }
});

"B" is keycode 66; however, it fires when i press "b", and alerts 66, which is the capital B keycode. little 'b' should alert "98"

I tried this in both firefox, and chrome.

PlantTheIdea
  • 16,061
  • 5
  • 35
  • 40
Ragas Dev
  • 11
  • 2

1 Answers1

0

change the event to keypress if you want case sensitive keycodes.

$(document).keypress(function(event) { // the event variable contains the key pressed
   if (event.which == x+65) { 
      alert(numToChar(x));
   }
});
Dvir
  • 3,287
  • 1
  • 21
  • 33