You are on page 1of 13

Supporting the Microsoft .NET Developer Community.

Log In

Helping Software Professionals Build Better Software Better


HomeArticlesJavascript Char Codes (Key Codes)

Home

Search

Articles

Categories

About

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
ARTICLE TYPES LANGUAGE ELEMENTS LANGUAGES TECHNOLOGIES

Subscribe for news, updates and more:


Email:

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

joy
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

reply

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 - !@#$%^&*()_+{}|:"<>?

reply

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

reply

Amit
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>CharCodesdoJavascript</title> </head> <body> <tablestyle="border:1pxsolidblack"id="tabela1"> <thead> <tr> <tdcolspan="2">TabeladeCharCodes</td> </tr> </thead> <TBODY></TBODY> </table> <body> <html> <script type="Text/Javascript"> vartabela=document.getElementById("tabela1") vartbody=tabela.getElementsByTagName("TBODY")[0] for (var i = 0; i <= 1000; i++) { varrow=document.createElement("TR") vartd1=document.createElement("TD") td1.appendChild(document.createTextNode(i+"")) vartd2=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.

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.


Thanks

reply

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.


how about the left click mouse button key?

reply

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


mouse?

reply

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

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.


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

reply

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?

reply

tom

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 i.own.u.help@gmail.com Thanks in advance

reply

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

reply

nulll

Posted 2009 May 12 07:49 AM.


any way it is helpful thnx

reply

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

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.


forward slash : 191 notcorect forward slash : 47 is corect

reply

amir

Posted 2009 Aug 05 06:04 AM.


The position of the special characters depends on the language of the keyboard, so that

reply

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


press 5 on numpad (numlock off)

reply

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.


key code for @ and _?

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.

vash

Posted 2010 Jun 10 10:51 AM.


What is char code for Mouse click

reply

Karthik

Posted 2010 Jun 10 10:52 AM.


What is char code for Mouse click

reply

Karthik
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";

reply

Kenneth

Posted 2010 Oct 12 06:27 AM.


this is very good

reply

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: http://unixpapa.com/js/key.html

reply

Nick

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.

reply

Lego

Posted 2011 Mar 07 03:04 AM.


The char code of y and Y are not same y=121 Y=89 I check It

reply

Lego(Susho)

Posted 2011 Mar 09 15:49 PM.


where is keycode 47?

reply

JSscholar

Posted 2011 Mar 09 15:50 PM.


What is keycode 47?

reply

JSscholar

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

reply

vinothkumar

Posted 2011 Apr 03 16:31 PM.


these are used like this window.onkeydown=function(e){ }; works with keyup too

reply

v9xx

Posted 2011 Apr 06 09:53 AM.


Gracias por los codigos

reply

rgf_py

Posted 2011 Apr 19 23:44 PM.


Cannot do with the keycode for comma as 188....

reply

Razack

Posted 2011 Apr 20 08:47 AM.


% and left arrow gives key code as 37. how to differenciate

reply

kavitha

Posted 2011 Apr 20 08:50 AM.


these two

reply

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

kavitha

Posted 2011 Jun 01 10:55 AM.


How can I write litte 2 on the top(for square function)?

reply

Idiot

Posted 2011 Jul 20 08:31 AM.


char code 31?

reply

Saranya

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

reply

Dharmendra

Posted 2011 Aug 29 20:07 PM.


I'm assuming no key press has a Javascript key code that equals zero?

reply

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.


Muito, show de bola mesmo. Obrigado.

reply

Paulo gomes

Posted 2011 Oct 25 04:52 AM.


GOOOOOOOOOOOOOOOOOOOD

reply

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

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.


Char code for comma is 44 also.... It works in both firefox and IE.

reply

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. Use the onKeyUp event handler and test for keycode 16. reply

Posted 2011 Nov 29 06:49 AM.


why?

reply

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

reply

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.


Very useful content. Thanks a lot.!

reply

Vishal Saxena

Posted 2011 Dec 07 06:21 AM.


How do I handle "shift"? like ")" = "shift 0"

reply

Lucy

Posted 2011 Dec 14 07:36 AM.


great information .Thanks a lot for this http://csharpektroncmssql.blogspot.com

reply

bhaskar

Posted 2011 Dec 29 12:24 PM.


with numpad 6 key . please check it. thanks

reply

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

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

reply

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.

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

reply

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

Posted 2012 Feb 09 05:10 AM.


very interesting

reply

mubarakmarafa

Posted 2012 Feb 10 14:14 PM.


very good web site

reply

tom

Posted 2012 Feb 20 04:03 AM.


Thanks, Is very good informations.

reply

Ali

Posted 2012 Feb 24 23:15 PM.


What about the lowercase letter "w"

reply

Henry Jonas

Posted 2012 Feb 25 20:17 PM.

reply

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

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


xde

reply

allonelords2

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.

reply

naing

Posted 2012 Apr 09 14:22 PM.


whooopooo hoooooooo

reply

jackoftrades

Posted 2012 Apr 24 20:51 PM.


How i can get code for that above keycode. i want to implement it in javascript?

reply

ravian

Posted 2012 Apr 25 05:50 AM.


I am not able to find key codes for Shift + keys.

reply

Satish

Posted 2012 Apr 28 04:05 AM.


how to get a registration key for VERYPDF2WORD 3.0

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>

Submit

Please type text as shown in the image at left.

Copyright Cambia Research 2002-2012. All rights reserved. Contactmeatsteveatcambiaresearchdotcom.

You might also like