Friday, March 17, 2006

Diff'rent [key]Strokes

I found one disadvantage to writing code on a laptop:

I added some functionality to a web app that filters keystrokes using client script so that only numbers could be entered into textboxes. I also had to allow for Delete, Backspace, Enter, decimal point, and Arrow Keys. But, all other keystrokes were just simply ignored.

And, then comes demo day. I go to the client's location, and we pull up the web application in her browser. Everything looks great. I tell her, "Go ahead and enter numbers. Try some letters and symbols, too."

What does she do? Immediately tries to type numbers using the numeric keypad on her full-size keyboard.

What does my script do? Filter out those keypresses because it did not recognize them as being numeric. Blah!

It seems that the number keys across the top of your keyboard and the number keys in the keypad have different keycodes, which actually makes a lot of sense. But, since I developed the site using a laptop, it didn't even occur to me to test the 10-key functionality.

For reference the keyCodes for 0-9 are:

"regular" numbers: 0x30 - 0x39
"number pad" numbers: 0x60 - 0x69

The decimal point (period) also has different keyCodes. 0xbe for the "regular", and 0x6e for the "number pad".