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.

没有正确的解决方案

其他提示

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));
   }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top