jQuery Keycode Cheatsheet

These are just Javascript keycodes, but when I searched originally I typed in “jQuery keycodes” and didn’t get much. This should be of help to someone in any case. Cheat away!

It’s useful for when you’re using the keydown, keypress, and keyup functions in jQuery. You’d use them in a way like this:

$('#textbox').keyup(function (e) {
if (e.keyCode == 13) {
alert('Enter key pressed!');
}
});

Key Keycode
Enter 13
Up arrow 38
Down arrow 40
Left arrow 37
Right arrow 39
Escape 27
Spacebar 32
Ctrl 17
Alt 18
Tab 9
Shift 16
Caps-lock 20
Windows key 91
Windows option key 93
Backspace 8
Home 36
End 35
Insert 45
Delete 46
Page Up 33
Page Down 34
Numlock 144
F1-F12 112-123
Print-screen ??
Scroll-lock 145
Pause-break 19

Enjoy!

  • http://fanani.net/ Fanani M. Ihsan

    thank , nice post

  • http://fanani.net/ Fanani M. Ihsan

    thank , nice post

  • http://www.facebook.com/Herb.E.Ness Andrew Stephan

    Very useful. Thank you for posting this.

  • Nander Cirkel

    Thank you, saved me a LOT of testing!

  • Xxxx

    whats printscreen?

  • Dennis

    Thank you!

  • Sillytwat

    It allows you to print what is on the screen

  • Ashfaq Ahmed

    what about print screen ?

  • http://quire.tesseractengine.com/ Mark Quire

    And they were useful, thank you Mike!

  • Theo Hubenet

    Printscreen is 44, and you can check yourself:
    $(‘#textbox’).keyup(function (e) {
    alert(e.keyCode);
    });

  • Rock

    It is not working for Caps key.

  • Vijay Kumar

    All the keys are working fine.. but Spacebar
    32 is not working..plz help..

  • HoneyPot FP

    some keycodes change depending on your keyboard layout (dvorak, qwert) or browser. the ideal is do something like “var enter=13;” then compare if keycode =enter;
    i dont know how to solve the diferent keyboard layout issues but i guess jquery has something for it..

  • Pingback: jQuery?keypress?????keyCode???????? | kanonji????

  • Myles

    Thank you *very* much

  • http://naikk.in/ Ukaza Perdana

    Thank you!

  • Aaron Shumaker

    And for the love of all that is holy please comment these magic values when you use them. I don’t want to have to do a reverse search for keycode “50” through a dozen sites to figure out what it is your code that I inherited is supposed to be doing.

  • kokoala

    can we do combo?ALt+Enter+P+CApsLock

  • eddyrakov

    sure, you can do it writing something like if (e.ctrlKey && e.shiftKey) {
    //do smth

    }

  • Pingback: How to: jQuery Event Keypress: Which key was pressed? | SevenNet

  • Pingback: Solution: jQuery Event Keypress: Which key was pressed? #dev #it #computers | Technical information for you

  • Pingback: Fixed jQuery Event Keypress: Which key was pressed? #dev #it #asnwer | Good Answer

  • http://twitter.com/samifouad Sami F

    If it helps anyone, letters A through Z capitalized are 65-90 and A-Z lower case is 97-122.

  • Pingback: jquery focusout == submit - - ENTITY

  • devi

    can anybody tell
    In my jquery text allow only alphanumeric or alpha alone but not numbers alone and the special characters are only @ and _ only

  • http://bobste.in/ Bob Stein

    Shouldn’t this be using e.which instead of e.keyCode?

    From http://api.jquery.com/event.which/ it says “It is recommended to watch event.whichfor keyboard key input.”

    Also http://stackoverflow.com/a/4471635/673991

  • Derek

    You sir are utterly and completely awesome did you know that?