If your project doesn't work, look for the part that you didn't think was important. --Arthur Bloch
Welcome to my blog and project site for Microsoft.NET development.

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:
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,051,172 times (1,349 times today).
Article TypesLanguage ElementsLanguagesTechnologies
ReferenceText and StringsJavascriptWeb 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!    

Untitled Page

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
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
 
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
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
 
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
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

Back to Top

User Comments (83)

Posted 2007 Mar 01 18:58 PM. reply
"Prnt Scrn SysRq " key code equals ?

joy
Reply 2007 Mar 01 22:59 PM by steve. reply
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.
Replied 2009 Feb 03 03:16 AM by Shaheen. reply
127 and 155 are key codes of what keys
Replied 2010 Feb 10 08:21 AM by Ramana. reply
154
Replied 2010 Jun 18 01:37 AM by Dinesh. reply
44
Replied 2011 Nov 28 03:57 AM by keycode. reply
what is mean by keycode in javascript?
Posted 2007 Mar 13 10:18 AM. reply
Great list! But I don't see the space bar. It is 32

Pat Markland
Reply 2007 Mar 13 21:31 PM by steve. reply
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.
Replied 2010 Apr 04 12:41 PM by Deibid. reply
Thank you, I also needed that.
Replied 2011 Feb 23 00:20 AM by Anonymous. reply
Thanks I needed it too!
Replied 2011 Jul 28 09:21 AM by Glide. reply
Thanks me too :)
Posted 2007 May 10 21:17 PM. reply
There's a whole lot of punctuation missing - !@#$%^&*()_+{}|:"<>?

Bill
Replied 2007 May 17 14:28 PM by Adam. reply
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.
Posted 2007 May 16 09:58 AM. reply
Excellent & very useful, thanks!!

Amit
Replied 2007 Jun 01 09:17 AM by Rafael Fotnoura. reply
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>
Replied 2008 Jul 24 05:37 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 2008 Jul 24 05:42 AM by Seryoga. reply
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.


<--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
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>
Posted 2007 Jun 11 07:33 AM. reply
Thanks

Atmaram
Posted 2007 Aug 02 15:10 PM. reply
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)

Derek Detweiler
Reply 2007 Aug 02 21:38 PM by steve. reply
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!
Posted 2007 Nov 07 22:31 PM. reply
how about the left click mouse button key?

cante
Replied 2007 Nov 22 07:42 AM by lotuzwine. reply
dont think that may be a keycode, but another event property
Replied 2008 Jan 09 11:15 AM by Quaza. reply
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.
Replied 2008 Mar 14 15:52 PM by Jason Miller. reply
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. };
Posted 2008 Apr 15 05:52 AM. reply
Is it possible to capture scrolling up, down or clicking down with the scroll wheel on a mouse?

Will
Replied 2008 Sep 17 08:34 AM by Benjamin M. A'Lee. reply
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.
Posted 2008 Oct 19 13:57 PM. reply
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

Jonathan Tang
Posted 2009 Jan 14 21:18 PM. reply
The way you capture all the browser shortcut key is really nice.
How does that work?

tom
Replied 2009 Mar 08 06:19 AM by Fabio999. reply
I need the key code for the reload button in browser help me please! send email to i.own.u.help@gmail.com Thanks in advance
Posted 2009 Mar 12 16:22 PM. reply
You could use the function
charCodeAt
to get the code of a character
ex:
alert(String.charCodeAt('c'));
will alert 99

nulll
Posted 2009 May 12 07:49 AM. reply
the code missing ascii value of some letters example Captial letters and print screen etc any way it is helpful thnx

ajay
Replied 2009 May 13 10:12 AM by Steve. reply
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.
Posted 2009 May 24 06:27 AM. reply
forward slash : 191 notcorect
forward slash : 47 is corect

amir
Posted 2009 Aug 05 06:04 AM. reply
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.

Anna
Posted 2009 Oct 29 10:35 AM. reply
press 5 on numpad (numlock off)

Anonymous
Reply 2010 Jan 27 13:08 PM by steve. reply
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.
Posted 2010 Jan 20 01:04 AM. reply
key code for @ and _?

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.

vash
Posted 2010 Jun 10 10:51 AM. reply
What is char code for Mouse click

Karthik
Posted 2010 Jun 10 10:52 AM. reply
What is char code for Mouse click

Karthik
Replied 2010 Jul 22 03:23 AM by Truck3r. reply
Why don't you try typing a mouse click in the test box at the top of the page...
Posted 2010 Jul 22 12:50 PM. reply
keys[173]="mute";
keys[174]="vol. down";
keys[175]="vol. up";
keys[176]="forward";
keys[177]="back";
keys[178]="stop";
keys[179]="play/pause";

Kenneth
Posted 2010 Oct 12 06:27 AM. reply
this is very good

sajid ali
Posted 2010 Dec 12 16:01 PM. reply
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

Nick
Posted 2011 Mar 07 02:48 AM. reply
I want the char code of Y and y, I don't know wheather the both are same or not.

Lego
Posted 2011 Mar 07 03:04 AM. reply
The char code of y and Y are not same

y=121
Y=89

I check It

Lego(Susho)
Posted 2011 Mar 09 15:49 PM. reply
where is keycode 47?

JSscholar
Posted 2011 Mar 09 15:50 PM. reply
What is keycode 47?

JSscholar
Posted 2011 Mar 24 06:29 AM. reply
This is wrong...

For Hyphen -> the key code is 45.

But here 45 is given for "insert" key.

:(

vinothkumar
Posted 2011 Apr 03 16:31 PM. reply
these are used like this
window.onkeydown=function(e){
};
works with keyup too

v9xx
Posted 2011 Apr 06 09:53 AM. reply
Gracias por los codigos

rgf_py
Posted 2011 Apr 19 23:44 PM. reply
Cannot do with the keycode for comma as 188....

Razack
Posted 2011 Apr 20 08:47 AM. reply
% and left arrow gives key code as 37. how to differenciate

kavitha
Posted 2011 Apr 20 08:50 AM. reply
% and left arrow gives key code as 37. how to differenciate. i have different condition for these two

kavitha
Posted 2011 Jun 01 10:55 AM. reply
How can I write litte 2 on the top(for square function)?

Idiot
Posted 2011 Jul 20 08:31 AM. reply
char code 31?

Saranya
Posted 2011 Aug 10 00:25 AM. reply
How to set the NULL value in textbox if user press any key from 0-9..
Thanks in advance

Dharmendra
Posted 2011 Aug 29 20:07 PM. reply
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)

Joey
Posted 2011 Sep 16 06:18 AM. reply
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 vasanth_dlj@rediffmail.com

vasanth
Posted 2011 Sep 17 20:01 PM. reply
Muito, show de bola mesmo.
Obrigado.

Paulo gomes
Posted 2011 Oct 25 04:52 AM. reply
GOOOOOOOOOOOOOOOOOOOD

aNIL
Reply 2011 Oct 30 23:38 PM by steve. reply
Is that "GOD" or "GOOD"? :)
Posted 2011 Oct 31 18:25 PM. 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?

Robert G
Posted 2011 Nov 17 03:18 AM. reply
Char code for comma is 44 also.... It works in both firefox and IE.

jsDeveloper
Posted 2011 Nov 21 16:38 PM. reply
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 ?

Dmike92
Replied 2011 Dec 01 08:46 AM by TimS. reply
Use the onKeyUp event handler and test for keycode 16.
Posted 2011 Nov 29 06:49 AM. reply
Using 74 for j doesn't work for me. I use 106 in my script and it works as j. Anyone know why?

Pablo Honey
Replied 2011 Dec 23 05:05 AM by JP. reply
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.
Posted 2011 Dec 01 08:43 AM. reply
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.

TimS
Posted 2011 Dec 05 03:47 AM. reply
Very useful content. Thanks a lot.!

Vishal Saxena
Posted 2011 Dec 07 06:21 AM. reply
How do I handle "shift"? like ")" = "shift 0"

Lucy
Posted 2011 Dec 14 07:36 AM. reply
great information .Thanks a lot for this http://csharpektroncmssql.blogspot.com

bhaskar
Posted 2011 Dec 29 12:24 PM. 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

ramin
Reply 2011 Dec 29 23:06 PM by steve. reply
I still get 70 for the f key and 102 for numpad 6.
Posted 2012 Jan 02 01:09 AM. reply
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.

muhammad shkeel
Posted 2012 Jan 04 06:08 AM. reply
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

Rancho
Posted 2012 Jan 14 01:20 AM. reply
u r download a nice coding

khushi
Posted 2012 Jan 17 01:06 AM. reply
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.

Nareshreddy Kola
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.