Firefox能检测MetaKey吗? [英] Can Firefox detect MetaKey?
问题描述
KeyboardEvent.metaKey
应该检测到它,但总是返回false。 (您可以在 Firefox的典型事件 - z : b Chrome针对Windows的典型事件 - z : p> 使用 Windows 键作为修饰符: 使用 Windows 键会有问题。 Windows会对许多按键组合作出反应,包括那些只是由用户执行的轻微错误键,而不是按照需要小心。您可能最好使用不同的修饰键,或者不包含 Windows 键的修饰键组合。 一般的键盘快捷键: I'm working on a Firefox extension and struggle with the meta key (Windows key on my keyboard). I can reproduce this with Firefox 48.0 on KDE 16.08 / Gentoo and Firefox 47.0.1 on Windows 10. I also tried all combinations of Ctrl, Shift, and Alt but nothing registered as meta. Chrome 53.0 does not have that problem, btw. No, and Yes: Firefox's current interpretation of the Windows key (and probably the Mac Command, but I have not tested) is contrary to the documentation at KeyboardEvent.metaKey. Either the Firefox code needs to change, or the documentation. At a minimum, the documentation should state the current situation. Without explanation of why this behavior is currently this way, I would consider it a bug in Firefox. Meanwhile, I have updated the KeyboardEvent.metaKey page on MDN with a note that the Windows key does cause In harmonizing the documentation page for nsIDOMWindowUtils with the source code (nsIDOMWindowUtils, UIEvent.cpp), I noticed in the source that additional modifier codes had been added, including If you want to know that the Windows key was pressed when an event you are handling occurred, you will have to use handlers on both Typical Windows events ( The following was the console log after pressing and releasing the Windows key while monitoring Firefox Typical events for Windows-z: Chrome Typical events for Windows-z: Using the Windows key as a modifier: Using the Windows key will be problematic. Windows will react to many key combinations including ones that are just slight mis-keyings performed by a user that is not being quite as careful as required. You are probably better off using a different modifier key, or combination of modifier keys that does not include the Windows key. Another example: Alt-Windows-z results in a full sequence of 3 Keyboard Shortcuts in general: 这篇关于Firefox能检测MetaKey吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b
正如您在上面的屏幕截图中所看到的,您不会获得 Windows的完整序列 - 在Firefox或Chrome中的 z 。与其他关键组合相比, z 缺少 keydown
事件。为什么这个事件没有被解雇我不清楚。我怀疑它是被Windows吞噬的。
keydown
事件的完整序列, Firefox中的code> keypress 事件和3 keyup
事件,而在Chrome中,顺序不会触发键盘
事件。
键盘组合分配给不同的任务,从操作系统到操作系统,浏览器到浏览器,以及用户到用户。一般来说,如果您想要在通常会发布的加载项中使用键盘快捷方式,最佳操作方法是使用默认键盘快捷方式,但允许用户选择为每个操作使用哪个快捷方式,或者即使有一个行动的捷径。实际情况是,用户会遇到与其他应用程序和浏览器扩展冲突。取决于您正在编写的扩展类型,更改键盘快捷键可能会,也可能不会,现在可能。KeyboardEvent.metaKey
is supposed to detect it but always returns false. (You can try it out on MDN or even easier in the jQuery API docs.)
Yes, Firefox can detect the Windows key, but not as the "Meta" key. Both keyup
and keydown
events are fired for that key, but not a keypress
event. Chrome also fires events similarly (no keypress
). The keyCode
is the same on both Chrome and Firefox, but what they consider the key to be is different between the two. Chrome considers the key to be the "Meta" key, while Firefox considers it to be the "OS" key. Thus, Firefox does not set the metaKey
property to true
, because from Firefox's point of view, the "Meta" key is not being pressed.metaKey
to be true (you may have to press Ctrl-F5 to refresh the page). MODIFIER_OS
to indicate the Windows key separate from a "Meta" key. I did not look into when exactly this change was made.keydown
and keyup
that watch for and track the current state of the Windows key.keydown
shown in full): keydown
, keypress
input
and keyup
events.
As you can see in the above screenshots, you don't get a full sequence of events for Windows-z in either Firefox or Chrome. Compared to other key combos both are missing the keydown
event for the z. Why that event was not fired is not clear to me. I suspect that it was swallowed by Windows.keydown
events, a keypress
event, and 3 keyup
events in Firefox, whereas in Chrome the sequence does not fire the keypress
event.
The key combinations that are already assigned to different tasks vary from OS to OS, browser to browser, and user to user. In general, if you are wanting to use a keyboard shortcut in an add-on which you are generally releasing, the best course of action is to have default keyboard shortcuts, but allow the user the option to define what shortcut to use for each action, or even if there is a shortcut for the action. The reality is that users will run into conflicts with other applications and browser extensions. Depending on what type of extension you are writing, changing keyboard shortcuts may, or may not, be possible at this time.