1

I notice that when I listen for a keypress the character codes show up differently in Chrome and IE. Does anyone know why this is happing?

Chrome:

numpad key: 0, String.fromCharCode(48) => "0"
numpad key: 1, String.fromCharCode(49) => "1"
numpad key: 2, String.fromCharCode(50) => "2"
numpad key: 3, String.fromCharCode(51) => "3"
numpad key: 4, String.fromCharCode(52) => "4"
numpad key: 5, String.fromCharCode(53) => "5"
numpad key: 6, String.fromCharCode(54) => "6"
numpad key: 7, String.fromCharCode(55) => "7"
numpad key: 8, String.fromCharCode(56) => "8"
numpad key: 9, String.fromCharCode(57) => "9"

IE:

numpad key: 0, String.fromCharCode(96)  => "`"
numpad key: 1, String.fromCharCode(97)  => "a"
numpad key: 2, String.fromCharCode(98)  => "b"
numpad key: 3, String.fromCharCode(99)  => "c"
numpad key: 4, String.fromCharCode(100) => "d"
numpad key: 5, String.fromCharCode(101) => "e"
numpad key: 6, String.fromCharCode(102) => "f"
numpad key: 7, String.fromCharCode(103) => "g"
numpad key: 8, String.fromCharCode(104) => "h"
numpad key: 9, String.fromCharCode(105) => "i"

I'm using jquery which should normalize event.keyCode and event.charCode:

$("#input").keypress(function(e){
    console.log e.which, String.fromCharCode(e.which)
})

This is different than this answer since it uses vanilla javascript e.keyCode instead of jquery e.which

I wonder if this has something to do with using a Windows Virtual Machine (Parallels Desktop).

Community
  • 1
  • 1
jwerre
  • 9,179
  • 9
  • 60
  • 69
  • You might simply want to manually map them instead: for values between 96 and 105, subtract 48 from them (basically, the numpad keys are their respective numeric keys are always 48 apart). – Terry May 16 '17 at 21:59
  • I'm not able to reproduce your problem in IE11 https://codepen.io/imjosh/pen/VbBEKz?editors=1111 – imjosh May 16 '17 at 22:35
  • Possible duplicate of [Get Correct keyCode for keypad(numpad) keys](http://stackoverflow.com/questions/5630918/get-correct-keycode-for-keypadnumpad-keys) – imjosh May 16 '17 at 23:20

0 Answers0