AnitaTang / js-hotkeys

Automatically exported from code.google.com/p/js-hotkeys
0 stars 0 forks source link

Number pad does not map correctly #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. Go to the demo page
2. Use the number pad (0-9) and watch what keys light up.  For me, the
numbers translated to the first corresponding letters in the alphabet.

Easy to produce on demo site, I also reproduced in the latest download.  I
am using Firefox v2.0.0.16

Original issue reported on code.google.com by thadw...@gmail.com on 27 Aug 2008 at 10:14

GoogleCodeExporter commented 8 years ago
It appears there is a little bit of magic based on the key event.  Check out the
similarity in the keycode/charcode for the numpad 2 an b keys:

'b'
keydown event
keyCode is 66
charCode is 0

keypress  event
keyCode is 0
charCode is 98

'numpad 2'
keydown event
keyCode is 98
charCode is 0

keypress event
keyCode is 0
charCode is 50

Original comment by thadw...@gmail.com on 27 Aug 2008 at 10:43

GoogleCodeExporter commented 8 years ago
I have a fix...basically the problem is that the number keys will resolve to
lowercase letters when resolved via: String.fromCharCode().   Where as letters 
on the
keyboard will resolve to upper case characters.  So...here's what I did:

1. added just below this.shift_nums = {...
this.keypad_nums = {"a":"1", "b":"2", "c":"3", "d":"4", "e":"5", "f":"6", 
"g":"7",
"h":"8", "i":"9"};

2. updated the inspector code to:
.....code before not changed
rawCharacter = String.fromCharCode(code),
character = that.keypad_nums[rawCharacter] || rawCharacter.toLowerCase(),
....code after not changed

Let me know if this does not work for you!

Original comment by thadw...@gmail.com on 27 Aug 2008 at 11:34

GoogleCodeExporter commented 8 years ago

Original comment by Afro.Sys...@gmail.com on 5 Sep 2008 at 4:06