Reference to self: JavaScript keyCode values for Finnish keyboards

Posted: (EET/GMT+2)

 

Lately, I've been doing a lot of work with ASP.NET 4.5 and jQuery work. One of the tasks have included realtime filtering for data returned from the backend, and for this purposes, I needed to dig the JavaScript event handling keyCodes. Assume for instance, you have an ASP.NET TextBox control, to which you associate a jQuery event handler like this:

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
  $(function () {
    $("#MainContent_TextBox1").keydown(function (e) {
      alert(e.keyCode);
    });
  });
</script>

The parameter "e" (for event) would give you the key code for the key that was pressed, but contrary to how things work in regular Windows desktop development, JavaScript keycodes are different. While googling away (binging as well), I didn't find many lists of keycodes, so I thought I'd write down one myself. So, if you need to handle these keys, here's a (shortened) list for U.S. keyboards on Windows:

8: "Backspace"
9: "Tab"
13: "Enter"
16: "Shift"
17: "Control"
18: "Alt"
19: "Pause"
20: "CapsLock"
27: "Esc"
32: "Spacebar"
33: "PageUp"
34: "PageDown"
35: "End"
36: "Home"
37: "Left"
38: "Up"
39: "Right"
40: "Down"
45: "Insert"
46: "Del"
48: "0"  <-- number keys above the letter keys, not numeric keypad
49: "1"
50: "2"
51: "3"
52: "4"
53: "5"
54: "6"
55: "7"
56: "8"
57: "9"
65: "A"
66: "B"
67: "C"
68: "D"
69: "E"
70: "F"
71: "G"
72: "H"
73: "I"
74: "J"
75: "K"
76: "L"
77: "M"
78: "N"
79: "O"
80: "P"
81: "Q"
82: "R"
83: "S"
84: "T"
85: "U"
86: "V"
87: "W"
88: "X"
89: "Y"
90: "Z"
96: "0"  <-- numeric keypad
97: "1"
98: "2"
99: "3"
100: "4"
101: "5"
102: "6"
103: "7"
104: "8"
105: "9"
106: "Multiply"
107: "Add"
109: "Subtract"
110: "Decimal"
111: "Divide"
112: "F1"
113: "F2"
114: "F3"
115: "F4"
116: "F5"
117: "F6"
118: "F7"
119: "F8"
120: "F9"
121: "F10"
122: "F11"
123: "F12"
186: ";"
187: "="
190: "."
191: "/"
192: "`"
219: "["
220: "\\"
221: "]"
222: "'"

Note two interesting things: small and capital letters ("a" vs. "A") are not being differentiated; instead, in the keydown event, you must yourself note the state of the keys. For example, the press of the Shift key generates the keycode 16.

Secondly, the keyCode values change per keyboard. Thus, I wanted to specifically document the Finnish language special characters, which are Å, Ä and Ö.

The keyCode values for these are (again, on Windows):

222: "ä"
192: "ö"
221: "å"

I actually have hard time locating a reference for this on MSDN, so you need to look elsewhere. However, here's a link that's pretty close.

Good luck!