Supporting the Microsoft .NET Developer Community.
Helping Software Professionals Build Better Software Better
Log In
Home → Articles → Javascript Char Codes (Key Codes) Home Search Articles Categories About
Welcome to my blog
about software
development and the
Microsoft stack.
I've been a full time .NET developer for
ten years, but I didn't start my
professional life as a programmer ...
more
Share/Print this page:
Subscribe for news, updates and more:
Email:
I respect your email privacy
Missouri River Rail Bridge - 12/2011. Copyright © Steve
Lautenschlager
Javascript Char Codes (Key Codes) Interactive Demonstration and Lookup Table
By steve on January 11, 2007.
Updated on January 26, 2012.
Viewed 1,191,611 times (1,229 times today).
ARTICLE TYPES LANGUAGE ELEMENTS LANGUAGES TECHNOLOGIES
Reference Text and Strings Javascript Web Browsers
Summary Javascript is often used on the browser client side to perform simple tasks that would otherwise require a full
postback to the server. Many of those simple tasks involve processing text or characters entered into a form
element on a web page, and it is often necessary to know the javascript keycode associated with a character.
Here is a reference.
Press a key in the text box below to see the corresponding Javascript key code. Or scroll down to see the full list.
Try it!
Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
Key Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
Key Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
User Comments (98)
"Prnt Scrn SysRq " key code equals ?
Ah, right. I forgot about that and had to go back and check.
The "Print Screen/SysRq" key appears to be a special case. All the keycodes above fire in at least the
onKeyDown event. However the Print Screen Key does not fire the onKeyDown or onKeyPress events. It
does sometimes fire the onKeyUp event when the page is freshly loaded. This behavior appears the same
in IE6 and Firefox.
When it does fire (intermittently) the keycode is 44.
127 and 155 are key codes of what keys
154
44
what is mean by keycode in javascript?
Great list! But I don't see the space bar. It is 32
Thanks for the kudos! Somehow it missed the list. I'll have to update that. If you enter the space bar
in the textbox above it works and the keycode is 32.
Back to Top
Posted 2007 Mar 01 18:58 PM. reply
joy
Reply 2007 Mar 01 22:59 PM by steve. reply
Replied 2009 Feb 03 03:16 AM by Shaheen. reply
Replied 2010 Feb 10 08:21 AM by Ramana. reply
Replied 2010 Jun 18 01:37 AM by Dinesh. reply
Replied 2011 Nov 28 03:57 AM by keycode. reply
Posted 2007 Mar 13 10:18 AM. reply
Pat Markland
Reply 2007 Mar 13 21:31 PM by steve. reply
Replied 2012 May 03 04:51 AM by buzz567. reply
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222
And I needed also. Thank you for clarifying.
Thank you, I also needed that.
Thanks I needed it too!
Thanks me too :)
There's a whole lot of punctuation missing - !@#$%^&*()_+|:"<>?
That is because punctuation doesn't let off a key code of their own. A key code refers to the key the
user pushed, not the output of the key. Example: a period (.) is keycode 190. If you make a > that
would be the same keycode because it is triggered off the same key.
You can just block all !@# ... with e.shiftKey that will block once the user has pressed trhe shit key
thus you dont need to worry about those special characters
Excellent & very useful, thanks!!
I've made a script to create a full Javascript charcode table; see below:
<html>
<head>
<title>CharCodes do Javascript</title>
</head>
<body>
<table style="border: 1px solid black;" id="tabela1">
<thead>
<tr>
<td colspan="2">Tabela de CharCodes</td>
</tr>
</thead>
<TBODY></TBODY>
</table>
<body>
<html>
<script type="Text/Javascript">
var tabela = document.getElementById("tabela1");
var tbody = tabela.getElementsByTagName("TBODY")[0];
for (var i = 0; i <= 1000; i++)
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.appendChild(document.createTextNode(i + " "));
var td2 = document.createElement("TD");
td2.appendChild(document.createTextNode(String.fromCharCode(i) + " "));
row.appendChild(td1);
row.appendChild(td2);
tbody.appendChild(row);
</script>
<html>
<head>
<title>CharCodes do Javascript</title>
</head>
Replied 2010 Apr 04 12:41 PM by Deibid. reply
Replied 2011 Feb 23 00:20 AM by Anonymous. reply
Replied 2011 Jul 28 09:21 AM by Glide. reply
Posted 2007 May 10 21:17 PM. reply
Bill
Replied 2007 May 17 14:28 PM by Adam. reply
Replied 2012 May 04 01:47 AM by Jerome. reply
Posted 2007 May 16 09:58 AM. reply
Amit
Replied 2007 Jun 01 09:17 AM by Rafael Fotnoura. reply
Replied 2008 Jul 24 05:37 AM by Seryoga. reply
<body>
<table id="tabela1">
<thead>
<tr>
<td colspan="2">Tabela de CharCodes</td>
</tr>
</thead>
<TBODY></TBODY>
</table>
<body>
<html>
<script type="Text/Javascript">
var tabela = document.getElementById("tabela1");
var tbody = tabela.getElementsByTagName("TBODY")[0];
for (var i = 0; i <= 1000; i++)
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.appendChild(document.createTextNode(i + " "));
var td2 = document.createElement("TD");
td2.appendChild(document.createTextNode(String.fromCharCode(i) + " "));
row.appendChild(td1);
row.appendChild(td2);
tbody.appendChild(row);
</script>
</body>
</html>
at last! it will work or no???
anyway - to fix code, is needed to add table with proper id.
Thank You Rafael! It's helpful script.
Very nice code I have added some color and borders to the table to make things stand out a bit
better. This is the code: <html> <head> <title>Javascript Char Codes</title> </head> <body>
<table id="tabela1" border="2"> <thead bgcolor="yellow"> <tr> <td colspan="2">Javascript
CharCodes</td> </tr> </thead> <TBODY bgcolor="lime"></TBODY> </table> <body> <script
type="Text/Javascript"> var tabela = document.getElementById("tabela1"); var tbody =
tabela.getElementsByTagName("TBODY")[0]; for (var i = 0; i <= 1000; i++) var row =
document.createElement("TR"); var td1 = document.createElement("TD"); td1.appendChild
(document.createTextNode(i + " ")); var td2 = document.createElement("TD"); td2.appendChild
(document.createTextNode(String.fromCharCode(i) + " ")); row.appendChild(td1); row.appendChild
(td2); tbody.appendChild(row); </script> </body> </html>
Replied 2008 Jul 24 05:42 AM by Seryoga. reply
<--html> <--head> <--title>CharCodes do Javascript<--/title> <--/head> <--body> <--table id="tabela1"> <--thead> <--tr> <--td colspan="2">Tabela de CharCodes<--/td> <--/tr> <--/thead> <--TBODY><--/TBODY> <--/table> <--body> <--html> <--script type="Text/Javascript"> var tabela = document.getElementById("tabela1"); var tbody = tabela.getElementsByTagName("TBODY")[0]; for (var i = 0; i <--= 1000; i++) var row = document.createElement("TR"); var td1 = document.createElement("TD"); td1.appendChild(document.createTextNode(i + " ")); var td2 = document.createElement("TD"); td2.appendChild(document.createTextNode(String.fromCharCode(i) + " ")); row.appendChild(td1); row.appendChild(td2); tbody.appendChild(row); <--/script> <--/body> <--/html>
Replied 2011 Nov 27 04:27 AM by johnnie. reply
Thanks
Semi-colon is "59" on Firefox, not "186", so you need to capture both for compatibility.
(Not that many folks need to capture ";", but I did for navigational reasons... umbrare.com)
Good point. I see that the text box above gets it right for both cases, but the table does not include
59 for Firefox. Thanks!
how about the left click mouse button key?
dont think that may be a keycode, but another event property
its not, instead of a keycode, use on(press) or on(release) if its a button, and onDown if its a
movie clip. If its a click anywhere activator, then use onMouseDown.
This isn't flash/ActionScript, you dolt. textarea.onmousedown=function(e) if(!e)
e=window.event; if((e.which&&e.which!=2) || (e.button&&e.button!=2)) // Left click (actually,
just a *non* right-click. ;
Is it possible to capture scrolling up, down or clicking down with the scroll wheel on a
mouse?
You might check mouse buttons 3 (middle-click) 4 (scroll up), and 5 (scroll down). At least, that's
what they appear as outside of Javascript.
Key codes are heavily dependent upon browsers. There's a full table available at:
http://unixpapa.com/js/key.html
There's also a library that normalizes keycodes into a consistent set, available at:
http://jonathan.tang.name/code/js_keycode
The way you capture all the browser shortcut key is really nice.
How does that work?
Posted 2007 Jun 11 07:33 AM. reply
Atmaram
Posted 2007 Aug 02 15:10 PM. reply
Derek Detweiler
Reply 2007 Aug 02 21:38 PM by steve. reply
Posted 2007 Nov 07 22:31 PM. reply
cante
Replied 2007 Nov 22 07:42 AM by lotuzwine. reply
Replied 2008 Jan 09 11:15 AM by Quaza. reply
Replied 2008 Mar 14 15:52 PM by Jason Miller. reply
Posted 2008 Apr 15 05:52 AM. reply
Will
Replied 2008 Sep 17 08:34 AM by Benjamin M. A'Lee. reply
Posted 2008 Oct 19 13:57 PM. reply
Jonathan Tang
Posted 2009 Jan 14 21:18 PM. reply
tom
I need the key code for the reload button in browser help me please! send email to
[email protected] Thanks in advance
You could use the function
charCodeAt
to get the code of a character
ex:
alert(String.charCodeAt('c'));
will alert 99
the code missing ascii value of some letters example Captial letters and print screen etc
any way it is helpful thnx
This list is only for keycodes not characters. It identifies your keyboard keys, not key combinations.
Shift-c for example does not belong in this list.
forward slash : 191 notcorect
forward slash : 47 is corect
The position of the special characters depends on the language of the keyboard, so that
might have an effect on which key gives which code. For example the Finnish keyboard has /
(backslash) where this code presents ' (semicolon), and American keyboards naturally don't
have å, ä or ö. You should keep in mind that hard-coding the positions of the special
characters is language dependent. Think of it like this: Javascript can only determine "this
is the 13th key on the second row on the keyboard", it can't tell what character is actually
printed on that key.
press 5 on numpad (numlock off)
I wouldn't call it missing. Your keyboard doesn't give the num5 on the keypad any meaning when the
numlock is off so we don't show a "name." But the keycode of 12 is shown so the key could still be
handled by javascript code.
key code for @ and _?
Replied 2009 Mar 08 06:19 AM by Fabio999. reply
Posted 2009 Mar 12 16:22 PM. reply
nulll
Posted 2009 May 12 07:49 AM. reply
ajay
Replied 2009 May 13 10:12 AM by Steve. reply
Posted 2009 May 24 06:27 AM. reply
amir
Posted 2009 Aug 05 06:04 AM. reply
Anna
Posted 2009 Oct 29 10:35 AM. reply
Anonymous
Reply 2010 Jan 27 13:08 PM by steve. reply
Posted 2010 Jan 20 01:04 AM. reply
Devanand
Posted 2010 Feb 09 08:56 AM. reply
Why if i insert ,in javascript ,the block of the forward slash (char code 191) i can't use
the key 7 ?
the forward slash is the combo of shift+number7.
What is char code for Mouse click
What is char code for Mouse click
Why don't you try typing a mouse click in the test box at the top of the page...
keys[173]="mute";
keys[174]="vol. down";
keys[175]="vol. up";
keys[176]="forward";
keys[177]="back";
keys[178]="stop";
keys[179]="play/pause";
this is very good
I would like to point out that these are not standard across browsers for example:
- or _ is:
firefox: 109
IE : 189
Opera : 45
Chrome/Safari : 45(without shift) / 95 (with shift)
As you can see many keys can be drastically different.
there is a great article here about the maddness that is javascript key events:
http://unixpapa.com/js/key.html
I want the char code of Y and y, I don't know wheather the both are same or not.
vash
Posted 2010 Jun 10 10:51 AM. reply
Karthik
Posted 2010 Jun 10 10:52 AM. reply
Karthik
Replied 2010 Jul 22 03:23 AM by Truck3r. reply
Posted 2010 Jul 22 12:50 PM. reply
Kenneth
Posted 2010 Oct 12 06:27 AM. reply
sajid ali
Posted 2010 Dec 12 16:01 PM. reply
Nick
Posted 2011 Mar 07 02:48 AM. reply
Lego
The char code of y and Y are not same
y=121
Y=89
I check It
where is keycode 47?
What is keycode 47?
This is wrong...
For Hyphen -> the key code is 45.
But here 45 is given for "insert" key.
:(
these are used like this
window.onkeydown=function(e)
;
works with keyup too
Gracias por los codigos
Cannot do with the keycode for comma as 188....
% and left arrow gives key code as 37. how to differenciate
Posted 2011 Mar 07 03:04 AM. reply
Lego(Susho)
Posted 2011 Mar 09 15:49 PM. reply
JSscholar
Posted 2011 Mar 09 15:50 PM. reply
JSscholar
Posted 2011 Mar 24 06:29 AM. reply
vinothkumar
Posted 2011 Apr 03 16:31 PM. reply
v9xx
Posted 2011 Apr 06 09:53 AM. reply
rgf_py
Posted 2011 Apr 19 23:44 PM. reply
Razack
Posted 2011 Apr 20 08:47 AM. reply
kavitha
% and left arrow gives key code as 37. how to differenciate. i have different condition for
these two
How can I write litte 2 on the top(for square function)?
char code 31?
How to set the NULL value in textbox if user press any key from 0-9..
Thanks in advance
I'm assuming no key press has a Javascript key code that equals zero?
I have a mask over a text field that ensures the only text entered is numeric. For automated
testing, trying to put characters here only recognises the key code truncated to a single
digit, not the character. So 1 = 4, z = 9 and so on and so forth. If there were some way to
get a 0 I would be set.
(fixing the issue in flash would be more work)
how to handle keypress event in asp.net like if i enter a character in textbox a grid should
be displayed and database items having that character should be loaded the code should be in
c# or javascript if anyone knows how to do it please reply me at [email protected]
Muito, show de bola mesmo.
Obrigado.
GOOOOOOOOOOOOOOOOOOOD
Is that "GOD" or "GOOD"? :)
Posted 2011 Apr 20 08:50 AM. reply
kavitha
Posted 2011 Jun 01 10:55 AM. reply
Idiot
Posted 2011 Jul 20 08:31 AM. reply
Saranya
Posted 2011 Aug 10 00:25 AM. reply
Dharmendra
Posted 2011 Aug 29 20:07 PM. reply
Joey
Posted 2011 Sep 16 06:18 AM. reply
vasanth
Posted 2011 Sep 17 20:01 PM. reply
Paulo gomes
Posted 2011 Oct 25 04:52 AM. reply
aNIL
Reply 2011 Oct 30 23:38 PM by steve. reply
Hope you can help please. Require my Java script web page to transmit a CONTROL-F9. This
triggers a text to speech program to speak aloud complex, program created message. I think I
can use this script: function find() x = new ActiveXObject("WScript.Shell") x.SendKeys
(0x6600); I have been unable to confirm the VALUE of CONTROL-F9. Can you help?
Char code for comma is 44 also.... It works in both firefox and IE.
Hi, Thank for this great job. Anyone can help me ? I need to write the script to distinguish
upper from lower case letters ? I see that the Keycode for shift is 16 but how do I know
it's released ?
Use the onKeyUp event handler and test for keycode 16.
Using 74 for j doesn't work for me. I use 106 in my script and it works as j. Anyone know
why?
I have the same case as you! I am using this code to detect period and decimal point but it doesn't
work for me. I am using a Samsung laptop.
Key codes only represent individual keys - not combinations. They also can vary greatly
depending on the layout of your keyboard. At work I use a Dell QWERTY 12-function keyboard
with 3 sections, and this list is accurate for that.
Very useful content. Thanks a lot.!
How do I handle "shift"? like ")" = "shift 0"
great information .Thanks a lot for this http://csharpektroncmssql.blogspot.com
Posted 2011 Oct 31 18:25 PM. reply
Robert G
Posted 2011 Nov 17 03:18 AM. reply
jsDeveloper
Posted 2011 Nov 21 16:38 PM. reply
Dmike92
Replied 2011 Dec 01 08:46 AM by TimS. reply
Posted 2011 Nov 29 06:49 AM. reply
Pablo Honey
Replied 2011 Dec 23 05:05 AM by JP. reply
Posted 2011 Dec 01 08:43 AM. reply
TimS
Posted 2011 Dec 05 03:47 AM. reply
Vishal Saxena
Posted 2011 Dec 07 06:21 AM. reply
Lucy
Posted 2011 Dec 14 07:36 AM. reply
thanks for the list but has a problem. when press f key it returns 102 key that confilicted
with numpad 6 key . please check it. thanks
I still get 70 for the f key and 102 for numpad 6.
i want to create a javascript for adposting script but i was failer. i create many time but
fail plz help some one any one. I shall be very thankful to helper.
Please Provide the key code testing textbox for Combination keys. As of now the textbox is
jst taking single character. If shift + 0 is pressed to get the output of ) key code it does
not givs desired output
Key codes differ from character codes
u r download a nice coding
This is an awesome article...I appreciate your effort for creating such a nice utility. Here
we have a problem with Shift key combination. When ever you press Shift + <!> = Shift + 1
which is not an expected output. All special special characters which are on top of numerics
are treated as numerics and given same KeyCode. Please help us in this matter.
very interesting
very good web site
Thanks, Is very good informations.
bhaskar
Posted 2011 Dec 29 12:24 PM. reply
ramin
Reply 2011 Dec 29 23:06 PM by steve. reply
Posted 2012 Jan 02 01:09 AM. reply
muhammad shkeel
Posted 2012 Jan 04 06:08 AM. reply
Rancho
Replied 2012 Feb 15 06:33 AM by pepe. reply
Posted 2012 Jan 14 01:20 AM. reply
khushi
Posted 2012 Jan 17 01:06 AM. reply
Nareshreddy Kola
Posted 2012 Feb 09 05:10 AM. reply
mubarakmarafa
Posted 2012 Feb 10 14:14 PM. reply
tom
Posted 2012 Feb 20 04:03 AM. reply
Ali
What about the lowercase letter "w"
Also, for game systems! WII: Platform: "Nintendo Wii" Up: 175 (CAUTION! ALSO SCROLLS UP)
Down: 176 (CAUTION! ALSO SCROLLS DOWN) Left: 178 (CAUTION! ALSO SCROLLS LEFT) Right: 177
(CAUTION! ALSO SCROLLS RIGHT) -: 170 (CAUTION! ALSO ZOOMS OUT) +: 174 (CAUTION! ALSO ZOOMS
IN) 1: 172 2: 173 (CAUTION! ALSO SPLITS SCREEN INTO SINGLE COLUMN MODE) PS3: Platform:
"PLAYSTATION 3" Up: 38 Down: 40 Left: 37 Right: 39 X: 63 (CAUTION! ALSO CLICKS) Nintendo
3ds: Platform: "Nintendo 3ds" Up: 38 Down: 40 Left: 37 Right: 39 LG Smart TV: Platform:
"Linux 35230" 0-9: 48-57 Play: 445 Pause: 19 Rewind: 412 FF: 417 Tested on what I have
Forgot to mention that for the 3ds, A: 13
xde
I want to know how to show error message when I validate the text in the test box.
whooopooo hoooooooo
How i can get code for that above keycode. i want to implement it in javascript?
I am not able to find key codes for Shift + keys.
how to get a registration key for VERYPDF2WORD 3.0
Posted 2012 Feb 24 23:15 PM. reply
Henry Jonas
Posted 2012 Feb 25 20:17 PM. reply
tomy
Replied 2012 Feb 27 19:39 PM by tomy. reply
Posted 2012 Mar 10 16:53 PM. reply
allonelords2
Posted 2012 Mar 16 23:18 PM. reply
naing
Posted 2012 Apr 09 14:22 PM. reply
jackoftrades
Posted 2012 Apr 24 20:51 PM. reply
ravian
Posted 2012 Apr 25 05:50 AM. reply
Satish
Posted 2012 Apr 28 04:05 AM. reply
sri
Post Your Comment
You may post without logging in or login here.
Display Name: Required.
Email: Required. Will not be shown. Used for identicon.
Comment:
Allowed tags: <quote></quote>, <code></code>, <b></b>, <i></i>, <u></u>, <red></red>
Please type text as shown in the image at left.
Submit
Copyright © Cambia Research 2002-2012. All rights reserved.
Contact me at steve at cambiaresearch d o t c o m.