Questions tagged [keycode]

A number linked with specific key on keyboard in many languages. May be different for one key depending on browser or platform. Use this tag for questions about the keycode property in a language.

Many languages associate different keys on the keyboard with different numbers, called "keycodes". The keycode is not to be confused with the ASCII character code, though there are some similarities. For example, JavaScript interprets an A keypress as 65 (ASCII code for capital "A") whether or not the Shift key was pressed or Caps Lock was enabled.

For more information about the JavaScript property, see

For more information about the C# KeyEventArgs.KeyCode property, see the Microsoft documentation.

839 questions
275
votes
9 answers

KeyboardEvent.keyCode deprecated. What does this mean in practice?

According to MDN, we should most definitely not be using the .keyCode property. It is deprecated: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode On W3 school, this fact is played down and there is only a side note saying that…
Jason210
  • 2,990
  • 2
  • 17
  • 18
170
votes
10 answers

Get Character value from KeyCode in JavaScript... then trim

This is what I have now: $("input").bind("keydown",function(e){ var value = this.value + String.fromCharCode(e.keyCode); } If the e.keyCode may not be an ASCII character (Alt, backspace, del, arrows, etc.)... I would now need to trim these…
David Murdoch
  • 87,823
  • 39
  • 148
  • 191
100
votes
8 answers

Where can I find a list of Mac virtual key codes?

I'm using CGEventCreateKeyboardEvent and need to know what CGKeyCode values to use. Specifically, I am after the key code for the Command key. The docs give examples for other keys: z is 6, shift is 56. There must be a list of Mac virtual keycodes…
Nick Moore
  • 15,547
  • 6
  • 61
  • 83
89
votes
1 answer

"A namespace cannot directly contain members such as fields or methods"

I am trying to use this code for NET.reflector using Reflexil. I am trying to replace code with this: if(Input.GetKeyDown(KeyCode.Keypad5)) { int i = 0; Character localPlayer = PlayerClient.GetLocalPlayer().controllable.GetComponent();…
user3204732
  • 903
  • 1
  • 6
  • 4
84
votes
7 answers

What are the JavaScript KeyCodes?

What keycodes are available for JavaScript? If they're not the same for all browsers, please list the keycodes for each browser.
Web_Designer
  • 72,308
  • 93
  • 206
  • 262
75
votes
8 answers

Get the value of input text when enter key pressed

I am trying this: with some javascript to check whether the enter key is…
user2405469
  • 1,953
  • 2
  • 22
  • 43
70
votes
6 answers

Determine if JavaScript e.keyCode is a printable (non-control) character

I'd just like to know the range(s) of JavaScript keyCodes that correspond to typeable characters; or alternatively, the range of non-typeable (control) characters like backspace, escape, command, shift, etc. so I can ignore them. The reason I ask is…
devios1
  • 36,899
  • 45
  • 162
  • 260
68
votes
7 answers

How to know if .keyup() is a character key (jQuery)

How to know if .keyup() is a character key (jQuery) $("input").keyup(function() { if (key is a character) { //such as a b A b c 5 3 2 $ # ^ ! ^ * # ...etc not enter key or shift or Esc or space ...etc /* Do stuff */ } });
faressoft
  • 19,053
  • 44
  • 104
  • 146
67
votes
2 answers

How to convert keycode to character using javascript

How to convert keycode to character using javascript var key_code = 65; result should be character = "a";
faressoft
  • 19,053
  • 44
  • 104
  • 146
50
votes
8 answers

JavaScript KeyCode vs CharCode

The problem: Limit allowed characters in a HTML input to a-z A-Z only. For business requirements this needs to be done on KeyPress so that the character simply isnt allowed to even appear in the input. Tab, enter, arrows, backspace, shift are all…
Remotec
  • 10,304
  • 25
  • 105
  • 147
48
votes
3 answers

Where can I find a list of keyboard keycodes?

Is there a place where I can find all the keycodes for keys on a keyboard? (For example, the key up may be #114) I can't seem to find one no matter what I search :( Thanks!
PHPNooblet
  • 687
  • 1
  • 7
  • 15
44
votes
4 answers

How to get the Enter key within a textbox to trigger a function and not the first/default button

I am trying to get the Enter key to trigger a function when it is pressed when inside a certain textbox, and not trigger the first or default button. You can see an example of what is happening here: http://jsfiddle.net/cutsomeat/WZ6TM/1/ If you…
MarkieB
  • 547
  • 1
  • 6
  • 12
38
votes
13 answers

Convert to uppercase as user types using javascript

I want to convert lowercase chars to uppercase as the user types using javascript. Any suggestions are welcome. I have tried the following: $("#textbox").live('keypress', function (e) { if (e.which >= 97 && e.which <= 122) { var newKey =…
Butcher
  • 395
  • 1
  • 3
  • 4
38
votes
6 answers

How to convert ASCII character to CGKeyCode?

I need a function that, given a character, returns the CGKeyCode associated with the position of that character on the current keyboard layout. E.g., given "b", it should return kVK_ANSI_B if using U.S. QWERTY, or kVK_ANSI_N if using Dvorak. The…
Michael
  • 11,612
  • 10
  • 41
  • 43
38
votes
10 answers

Keycode is always zero in Chrome for Android

I need to detect the keycode for a custom search box on my website, but the keycode always returns as zero on Chrome for Android (except for backspace, which returns 8). Has anyone else experienced this, and how did you get around it? Our website…
barrrrrrrrrooo
  • 381
  • 1
  • 3
  • 6
1
2 3
55 56