May I know what is the keycode for hash sign (#)? I have searched through some resources but couldn't find. Is it possible to get keycode for this symbol? How about other punctuations? Thanks.
May I know what is the keycode for hash sign (#)? I have searched through some resources but couldn't find. Is it possible to get keycode for this symbol? How about other punctuations? Thanks.
Share Improve this question asked Nov 13, 2011 at 14:21 davidleedavidlee 6,16718 gold badges58 silver badges87 bronze badges 1- 1 link – Dmitry Teplyakov Commented Nov 13, 2011 at 14:28
3 Answers
Reset to default 11You can find out the keycodes for whatever letter by simply running this code (try it now in your console):
document.onkeypress = function (e) { console.log(e.which); };
Then just type the letter you're interested in, and it will show up in the console.
#
is 35
, btw.
It will be its ASCII value which is 35.
Full table can be found here.
However, assuming user is typing it by pressing Shift+3 then you'll need to catch the key code of the digit 3 (which is 51) plus check the shiftKey
property of the event
object: when true and the key code is 51 it means #
was typed.
(The above is correct only for specific keyboard layout, sorry)
Live test case using onkeypress
to detect the key stroke.
Some reason 35 wasnt working for me. The # keyCode is 51
worked for me