Supporting the Microsoft .NET Developer Community.

    Log In

Helping Software Professionals Build Better Software Better
Home → Articles → Javascript Char Codes (Key Codes)






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

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:
Missouri River Rail Bridge - 12/2011. Copyright © Steve Lautenschlager

Subscribe for news, updates and more:


Text and Strings


Web Browsers

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.
I respect your email privacy

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 backspace tab enter shift ctrl alt pause/break caps lock escape page up page down end home left arrow up arrow right arrow down arrow insert delete 0

Code 8 9 13 16 17 18 19 20 27 33 34 35 36 37 38 39 40 45 46 48  

Key e f g h i j k l m n o p q r s t u v w x

Code 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88  

Key numpad 8 numpad 9 multiply add subtract decimal point divide f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 num lock

Code 104 105 106 107 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 144

1 2 3 4 5 6 7 8 9 a b c d

49 50 51 52 53 54 55 56 57 65 66 67 68

y z left window key right window key select key numpad 0 numpad 1 numpad 2 numpad 3 numpad 4 numpad 5 numpad 6 numpad 7

89 90 91 92 93 96 97 98 99 100 101 102 103

scroll lock semi-colon equal sign comma dash period forward slash grave accent open bracket back slash close braket single quote

145 186 187 188 189 190 191 192 219 220 221 222

Back to Top

User Comments (98)
Posted 2007 Mar 01 18:58 PM.
"Prnt Scrn SysRq " key code equals ?


Reply 2007 Mar 01 22:59 PM by steve. 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. 127 and 155 are key codes of what keys Replied 2010 Feb 10 08:21 AM by Ramana. 154 Replied 2010 Jun 18 01:37 AM by Dinesh. 44 Replied 2011 Nov 28 03:57 AM by keycode. what is mean by keycode in javascript?  reply  reply  reply  reply  reply

Posted 2007 Mar 13 10:18 AM.
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 2012 May 03 04:51 AM by buzz567.  reply

And I needed also. Thank you for clarifying. Replied 2010 Apr 04 12:41 PM by Deibid. Thank you, I also needed that. Replied 2011 Feb 23 00:20 AM by Anonymous. Thanks I needed it too! Replied 2011 Jul 28 09:21 AM by Glide. Thanks me too :)  reply  reply  reply

Posted 2007 May 10 21:17 PM.
There's a whole lot of punctuation missing - !@#$%^&*()_+{}|:"<>?


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. Replied 2012 May 04 01:47 AM by Jerome.  reply

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

Posted 2007 May 16 09:58 AM.
Excellent & very useful, thanks!!


Replied 2007 Jun 01 09:17 AM by Rafael Fotnoura. 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. <html> <head> <title>CharCodes do Javascript</title> </head>  reply  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> Replied 2008 Jul 24 05:42 AM by Seryoga. 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.  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.


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.



Posted 2007 Aug 02 15:10 PM.


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

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.
how about the left click mouse button key?


Replied 2007 Nov 22 07:42 AM by lotuzwine. dont think that may be a keycode, but another event property Replied 2008 Jan 09 11:15 AM by Quaza.  reply  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. 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. };  reply

Posted 2008 Apr 15 05:52 AM.


Is it possible to capture scrolling up, down or clicking down with the scroll wheel on a

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.
Key codes are heavily dependent upon browsers. There's a full table available at: There's also a library that normalizes keycodes into a consistent set, available at:


Jonathan Tang

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



Replied 2009 Mar 08 06:19 AM by Fabio999. I need the key code for the reload button in browser help me please! send email to Thanks in advance


Posted 2009 Mar 12 16:22 PM.
You could use the function charCodeAt to get the code of a character ex: alert(String.charCodeAt('c')); will alert 99



Posted 2009 May 12 07:49 AM.
any way it is helpful thnx


the code missing ascii value of some letters example Captial letters and print screen etc

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.
forward slash : 191 notcorect forward slash : 47 is corect



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


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


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.
key code for @ and _?



Posted 2010 Feb 09 08:56 AM.


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.


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



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


Replied 2010 Jul 22 03:23 AM by Truck3r. Why don't you try typing a mouse click in the test box at the top of the page...  reply

Posted 2010 Jul 22 12:50 PM.
keys[173]="mute"; keys[174]="vol. down"; keys[175]="vol. up"; keys[176]="forward"; keys[177]="back"; keys[178]="stop"; keys[179]="play/pause";



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


sajid ali

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



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



Posted 2011 Mar 07 03:04 AM.
The char code of y and Y are not same y=121 Y=89 I check It



Posted 2011 Mar 09 15:49 PM.
where is keycode 47?



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



Posted 2011 Mar 24 06:29 AM.
This is wrong... For Hyphen -> the key code is 45. But here 45 is given for "insert" key. :(



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



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



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



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



Posted 2011 Apr 20 08:50 AM.
these two


% and left arrow gives key code as 37. how to differenciate. i have different condition for


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



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



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



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


Posted 2011 Sep 16 06:18 AM.


how to handle keypress event in 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


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


Paulo gomes

Posted 2011 Oct 25 04:52 AM.


Reply 2011 Oct 30 23:38 PM by steve. Is that "GOD" or "GOOD"? :)  reply

Posted 2011 Oct 31 18:25 PM.


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.
Char code for comma is 44 also.... It works in both firefox and IE.



Posted 2011 Nov 21 16:38 PM.


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 ?

Replied 2011 Dec 01 08:46 AM by TimS. Use the onKeyUp event handler and test for keycode 16.  reply

Posted 2011 Nov 29 06:49 AM.


Using 74 for j doesn't work for me. I use 106 in my script and it works as j. Anyone know

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


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


Vishal Saxena

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



Posted 2011 Dec 14 07:36 AM.
great information .Thanks a lot for this



Posted 2011 Dec 29 12:24 PM.
with numpad 6 key . please check it. thanks


thanks for the list but has a problem. when press f key it returns 102 key that confilicted

Reply 2011 Dec 29 23:06 PM by steve. I still get 70 for the f key and 102 for numpad 6.  reply

Posted 2012 Jan 02 01:09 AM.
fail plz help some one any one. I shall be very thankful to helper.


i want to create a javascript for adposting script but i was failer. i create many time but

muhammad shkeel

Posted 2012 Jan 04 06:08 AM.


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

Replied 2012 Feb 15 06:33 AM by pepe. Key codes differ from character codes  reply

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



Posted 2012 Jan 17 01:06 AM.


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

Posted 2012 Feb 09 05:10 AM.
very interesting



Posted 2012 Feb 10 14:14 PM.
very good web site



Posted 2012 Feb 20 04:03 AM.
Thanks, Is very good informations.



Posted 2012 Feb 24 23:15 PM.
What about the lowercase letter "w"


Henry Jonas

Posted 2012 Feb 25 20:17 PM.


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

Replied 2012 Feb 27 19:39 PM by tomy. Forgot to mention that for the 3ds, A: 13  reply

Posted 2012 Mar 10 16:53 PM.



Posted 2012 Mar 16 23:18 PM.
I want to know how to show error message when I validate the text in the test box.



Posted 2012 Apr 09 14:22 PM.
whooopooo hoooooooo



Posted 2012 Apr 24 20:51 PM.
How i can get code for that above keycode. i want to implement it in javascript?



Posted 2012 Apr 25 05:50 AM.
I am not able to find key codes for Shift + keys.



Posted 2012 Apr 28 04:05 AM.
how to get a registration key for VERYPDF2WORD 3.0



Post Your Comment
  You may post without logging in or login here.

Display Name:

Required. Will not be shown. Used for identicon.


Allowed tags: <quote></quote>, <code></code>, <b></b>, <i></i>, <u></u>, <red></red>  


  Please type text as shown in the image at left.

Copyright © Cambia Research 2002-2012. All rights reserved. Contact me at steve at cambiaresearch  d o t  c o m.

Sign up to vote on this title
UsefulNot useful