从键盘或数字键盘识别 2 键

发布于 2024-09-09 16:58:25 字数 146 浏览 3 评论 0原文

我想向我的网络应用程序添加键盘快捷键。

但对于其中之一,我需要能够区分使用小键盘输入的数字和在 qwerty 字符上方输入的数字(我的用例是法语键盘,所以它是 azerty,但我认为这不是问题)。我会将其与大写锁定激活的检测结合起来。

这可能吗?

I would like to add keyboard short-cuts to my web application.

But for one of them, I need to be able to distinguish between the digits entered with the numpad from the one entered above the qwerty chars (my use case is for French keyboards, so it's azerty, but I don't think it's a problem). I'll combine it with a detection of the caps lock activation.

Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

油焖大侠 2024-09-16 16:58:25

浏览器中的键码检测非常混乱:检查 quirksmode.org 兼容性表。

根据这个列表,不过,令我惊讶的是,实际上似乎可以区分两者:

Key      Code
------------------------------
2        50  
numpad 2 98

还没有尝试过,但绝对值得一试。

Keycode detection is pretty chaotic in browsers: Check the quirksmode.org compatibility table.

According to this list, though, surprisingly to me, it seems in fact to be possible to distinguish the two:

Key      Code
------------------------------
2        50  
numpad 2 98

Haven't tried this but it's definitely worth a try.

゛时过境迁 2024-09-16 16:58:25

阅读 keyCodeonkeyup 事件。

document.onkeyup = alertKeyPressed;       

function alertKeyPressed(){
     var keyPressed = event.keyCode;
     alert(keyPressed);
}

Read up on keyCode and the onkeyup event.

document.onkeyup = alertKeyPressed;       

function alertKeyPressed(){
     var keyPressed = event.keyCode;
     alert(keyPressed);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文