TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Whatthekeycode.com - quickly find a js keycode for any key

141 pointsby timparkeralmost 13 years ago

14 comments

jayferdalmost 13 years ago
Key codes are pretty good for little things, but they break down pretty quickly if you want international support. In Mathquill, we ended up just using a hidden textarea and a setTimeout, with a few hilarious hacks. The comments and commit history are worth a read: <a href="https://github.com/mathquill/mathquill/blob/dev/src/textarea.js" rel="nofollow">https://github.com/mathquill/mathquill/blob/dev/src/textarea...</a>
评论 #4478924 未加载
gokhanalmost 13 years ago
Nice, but fails for me with non-English characters on my keyboard, ğüşöçĞÜŞÖÇ, and can't differentiate i and ı.
评论 #4478827 未加载
评论 #4478666 未加载
deepakgalmost 13 years ago
Probably relevant to the discussion, the mousetrap library: <a href="http://craig.is/killing/mice" rel="nofollow">http://craig.is/killing/mice</a>
评论 #4479060 未加载
评论 #4479054 未加载
gibyboalmost 13 years ago
Heh, I've lost count of how many times I've written "document.onkeydown = function(e) { console.log(e.keyCode); }" to deal with this. This is probably easier, if I can remember it when I need it :)
anvandarealmost 13 years ago
DOM keycodes are kind of broken beyond repair[1]. They cannot be relied upon to determine precisely which character a user entered (even jQuery's charcode falls short here) because they do not take into account modifier keys, compositions, or locales.<p>[1] For a (detailed) explanation: <a href="http://unixpapa.com/js/key.html" rel="nofollow">http://unixpapa.com/js/key.html</a>
NVIalmost 13 years ago
I made something like this a while ago <a href="http://elv1s.ru/files/js/key-code-detector.html" rel="nofollow">http://elv1s.ru/files/js/key-code-detector.html</a>
kunilalmost 13 years ago
On an unrelated note, is there way to forbid sites to override ctrl+w? I hate it when a web page is not closed with a short cut.<p>edit: I am using firefox
评论 #4479535 未加载
评论 #4478832 未加载
goochtekalmost 13 years ago
It's kind of ironic that you can't bookmark it in Chrome using the ctrl+d shortcut when this is one of those perfect bookmark tools.
评论 #4478707 未加载
klibertpalmost 13 years ago
This: <a href="http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes" rel="nofollow">http://www.cambiaresearch.com/articles/15/javascript-char-co...</a> was sitting in my bookmarks for quite some time now... And will be there, because I use vrome which seems to capture the key presses when there's no input focused :(
TomGullenalmost 13 years ago
Nice! But shift-key doesn't work. For example if I want to get the code for +
评论 #4479032 未加载
DigitalSeaalmost 13 years ago
Anyone ever noticed that the print screen key is from what I can see, the only key on a conventional qwerty keyboard that doesn't have an event code? What's the reasoning for that?
ernestiparkalmost 13 years ago
The key that is being pressed should be shown on the page somewhere - though it would make it look uglier. But for a utility like this, probably won't matter all that much.
评论 #4479536 未加载
joefarishalmost 13 years ago
Doesn't work in IE8. I know IE8 isn't exactly the latest and greatest web browser but some of us are stuck using it at work!
评论 #4479367 未加载
princevermaalmost 13 years ago
it would be nice if it can simultaneously display appropriate JS code to bind for a particular key. Also, if it can recognize key combos like ctrl-alt-s
评论 #4479268 未加载
评论 #4479033 未加载