Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下一版可以用event.code代替event.keyCode吗? #445

Open
Tracked by #313
YuxuanWeng opened this issue Aug 29, 2023 · 3 comments
Open
Tracked by #313

下一版可以用event.code代替event.keyCode吗? #445

YuxuanWeng opened this issue Aug 29, 2023 · 3 comments

Comments

@YuxuanWeng
Copy link
Contributor

YuxuanWeng commented Aug 29, 2023

目前keyCode已经废弃蛮久的了(https://developer.mozilla.org/zh-CN/docs/Web/API/KeyboardEvent/keyCode)
keyCode目前发现,在input中使用shift+数字/字母的快捷键是,会遇到keyCode===229的情况,以及shift+小键盘按键的时候也会出现识别问题

@jaywcjlove
Copy link
Owner

@YuxuanWeng 下一个版本会舍弃一些兼容代码,但是 event.code 代替 event.keyCode 还需要斟酌

image

@YuxuanWeng
Copy link
Contributor Author

YuxuanWeng commented Sep 1, 2023

哦哦,好的,那有没有在event.code空的时候再使用keyCode呢?我目前是单对229的场景做了下兼容

var key = event.keyCode || event.which || event.charCode;
if (key === 229) {
  key = codeToKeyCodeMap[event.code] || key;
}

@jaywcjlove
Copy link
Owner

hotkeys-js/src/index.js

Lines 231 to 237 in 031bc4d

/**
* Collect bound keys
* If an Input Method Editor is processing key input and the event is keydown, return 229.
* https://stackoverflow.com/questions/25043934/is-it-ok-to-ignore-keydown-events-with-keycode-229
* http://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html
*/
if (_downKeys.indexOf(key) === -1 && key !== 229) _downKeys.push(key);

@YuxuanWeng 是不是上面的问题,目前没有办法测试数字键的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants