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
37
votes
7 answers

JQuery allow only two numbers after decimal point

I found the following JQuery function here which prevents a user from entering anything that's not a number or a single decimal. The function works well but I'd like to improve it to prevent the user from entering 3 or more decimal places i.e.…
user676567
  • 1,119
  • 9
  • 20
  • 39
33
votes
7 answers

C# How to translate virtual keycode to char?

I am trying to map a virtual keycode to a char. My code uses ProcessCmdKey to listen to WM_KEYDOWN which gives me access to the key pressed. For example, when I press single quote I get a key of 222 which I want to have it mapped to keychar 39 which…
Horas
  • 1,781
  • 3
  • 16
  • 11
29
votes
11 answers

How to detect that Ctrl+R was pressed?

I'm coding a function in jquery that executes if Ctrl+R is pressed but I can't seem to find out what the left and right ctrl keycodes are... Can someone please help? UPDATE ///this works $(document).keydown(function(e){ …
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
27
votes
6 answers

What is the KeyCode for ","(comma) and "."(dot) in .NET?

In my KeyDown EventHandler I need to know what is the KeyCode for "," and ".". I can't find them thats why I ask. Thanks!
Bosak
  • 2,103
  • 4
  • 24
  • 43
27
votes
4 answers

How to differentiate between 'Enter' and 'Return' keys in Javascript?

Some desktop apps treat the 'carriage return' key and the numpad's 'enter' key differently. I've noticed that these two keys generate the same keyCode (13) in Javascript (jQuery). Are they converted to be equal in the browser environment, or is it…
mikkelbreum
  • 3,021
  • 9
  • 38
  • 41
27
votes
4 answers

Can javascript tell the difference between left and right shift key?

Mostly this is a sanity check. The key code for both shift keys is 16. Does that mean it is actually impossible to distinguish a left and right shift events in a browser?
Weavermount
  • 746
  • 10
  • 19
25
votes
2 answers

How can I control the back button event in jQuery Mobile?

I tried to control back button, but I can’t. In here; Take control of the hardware back button using jQuery Mobile event.keyCode == 27 // That’s for escape event.keyCode == 8 // That’s for backspace...it's also working on browser, but it doesn’t…
Serkan
  • 641
  • 3
  • 11
  • 19
21
votes
5 answers

event.keycode not returning correct values in firefox

I am trying the following code for triggering a js method when space-bar is pressed within an input box. $('#j1').keypress (function (event){ alert(event.keycode) }); In firefox this returns correct value only when…
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
21
votes
3 answers

Which key does the e.metaKey refer to in JavaScript MouseEvent?

MouseEvent.metaKey doesn't seem to work. On both FireFox and Chrome, it returns false even if I hold the Win key while clicking: MDN states: The…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
20
votes
7 answers

Javascript: different keyCodes on different browsers?

So I've seen some forums posts about different browsers reporting differenct keyCodes, but everyone seems so avoid the "why?". I was trying to capture the colon (:) keyCode and realized that Firefox reports back e.keyCode 56. While Chrome reports…
Senica Gonzalez
  • 7,996
  • 16
  • 66
  • 108
20
votes
1 answer

List of hex keyboard scan codes and USB HID keyboard documentation

Where am I able to find a list of the hex keyboard scan codes for different keyboard layouts? I'm sending the key codes over a (fake) USB HID keyboard with the bash command echo -ne followed by the escaped hex key scan code and the HID device: echo…
Nico Hauser
  • 644
  • 2
  • 8
  • 17
20
votes
7 answers

javascript subtract(-) keycode

ok, i need my code to check if minus/subtract/- was pressed, if it was pressed i want an alert box to pop. i tried with both 109 and 189 key codes but i still don't get the desired result. although i press "-" i don't get that alert box
kmunky
  • 15,383
  • 17
  • 53
  • 64
19
votes
7 answers

How can I convert a key code into a char or string?

How to convert the keycode into char or string?? Here is the example code: public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub //Log.d("EditText", "It's Working...!" + event.getAction()); if…
ram
  • 3,487
  • 10
  • 33
  • 47
19
votes
8 answers

Allow only numbers and ctrl+a , ctrl+v , ctrl+c to a textbox

I am trying to allow users enter only numbers and copy and paste control to the textbox. I am able to restrict user to enter only numbers but copy,paste is not working for me help me to fix this. Here is my…
Suresh Pattu
  • 6,083
  • 16
  • 59
  • 91
18
votes
6 answers

What is the "M- notation" and where is it documented?

The man page of cat says: -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB What is the M- notation and where is it documented? Example: $cat log -A wrote 262144 bytes from file test.x in 9.853947s (25.979 KiB/s)^M$ ^M>…
eDeviser
  • 1,605
  • 2
  • 17
  • 44
1
2
3
55 56