最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get keycode for hash #? - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 11

You 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

发布评论

评论列表(0)

  1. 暂无评论