Beruflich Dokumente
Kultur Dokumente
Log In
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
Reference
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
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
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
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
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
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>
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>
reply
Atmaram
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!
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
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.
reply
Jonathan Tang
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
reply
nulll
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.
reply
amir
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
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.
reply
Devanand
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
reply
Karthik
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
reply
Kenneth
reply
sajid ali
reply
Nick
reply
Lego
reply
Lego(Susho)
reply
JSscholar
reply
JSscholar
reply
vinothkumar
reply
v9xx
reply
rgf_py
reply
Razack
reply
kavitha
reply
% and left arrow gives key code as 37. how to differenciate. i have different condition for
kavitha
reply
Idiot
reply
Saranya
reply
Dharmendra
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
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
reply
Paulo gomes
reply
aNIL
Reply 2011 Oct 30 23:38 PM by steve. Is that "GOD" or "GOOD"? :) reply
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
reply
jsDeveloper
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
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.
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
reply
Vishal Saxena
reply
Lucy
reply
bhaskar
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
reply
i want to create a javascript for adposting script but i was failer. i create many time but
muhammad shkeel
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
reply
khushi
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
reply
mubarakmarafa
reply
tom
reply
Ali
reply
Henry Jonas
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
reply
allonelords2
reply
naing
reply
jackoftrades
reply
ravian
reply
Satish
reply
sri
Display Name:
Required.
Email:
Required. Will not be shown. Used for identicon.
Comment:
Submit