问题描述
我正在为Firefox开发虚拟键盘扩展。此扩展程序的功能之一是将用户按下的键转换为另一种布局。
I am developing a virtual keyboard extension for Firefox. One of the features of this extension is converting the keys the user presses to another layout.
示例:我需要在Bashkir布局上键入文本,但我的操作系统不支持它。因此,我可以使用此虚拟键盘扩展名,而无需更改系统设置。
Example: I need to type text on Bashkir layout but my OS does not support it. So, I can use this virtual keyboard extension and not change the system settings.
在不支持多种语言的Windows XP上是必需的。
我使用了来检测按下了哪个键。我之所以使用它,是因为尽管系统布局仍然可以检测到键码。
It's needed on Windows XP which does not support many languages.I used event.keyCode
to detect which key was pressed. I used it because it detects the key code despite the system layout.
但是如果键盘为非英语布局,则我错过了Firefox, event.keyCode
在某些键上无法正常工作,即 和。
But I missed that in Firefox if the keyboard is a non-English layout, event.keyCode
doesn't work correctly with some keys, namely and .
如果键入键,则 keyCode
返回81,并且如果键入俄语,相同的键 keyCode
也会返回 81
。但是,如果我键入键,则 keyCode
返回 219
,并且如果我输入俄语,即相同的键, keyCode
返回 0
。
If I type the key, keyCode
returns 81 and if I type in Russian , which is the same key, keyCode
also returns 81
. But If I type the key, keyCode
returns 219
and if I type in Russian , which is the same key, keyCode
returns 0
.
是否存在任何 keyCode
替代方案?
Do any keyCode
alternatives exist?
推荐答案
。它们包括:
- (已弃用)
- (已弃用)
- (已弃用)
- KeyboardEvent.altKey
- KeyboardEvent.charCode (Deprecated)
- KeyboardEvent.code
- KeyboardEvent.ctrlKey
- KeyboardEvent.isComposing
- KeyboardEvent.key
- KeyboardEvent.keyCode (Deprecated)
- KeyboardEvent.location
- KeyboardEvent.metaKey
- KeyboardEvent.shiftKey
- KeyboardEvent.which (Deprecated)
似乎是可以为您提供最佳信息的信息,并且已被弃用。但是,只有Firefox的Nightly,Aurora和Developer Edition中的Firefox 32.0中才提供此功能。从Firefox 38.0起,它将或将在标准发行版中提供。
KeyboardEvent.code appears to be the one which may provide you with the best information, and is not deprecated. However, it is only available from Firefox 32.0 in the Nightly, Aurora and Developer Editions of Firefox. From Firefox 38.0 and onwards it is, or will be, available in the standard release version.
您可能必须尝试使用 charCode的各种组合
,代码
,键
, keyCode
和其中
以获取所需的信息。如果您希望支持各种Firefox版本,则几乎可以肯定必须使用不同属性的组合。
You may have to experiment with various combinations of charCode
, code
, key
, keyCode
, and which
to get the information you desire. If you desire to support a wide range of Firefox releases, you will almost certainly have to use a combination of different properties.
这篇关于event.keyCode替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!