Handle CapsLock on macOS
Modifiers behave a bit oddly on macOS, causing weird CapsLock events to be sent by the browsers.
This commit is contained in:
parent
bf43c26319
commit
634cc1ba46
|
@ -146,6 +146,17 @@ Keyboard.prototype = {
|
||||||
keysym = this._keyDownList[code];
|
keysym = this._keyDownList[code];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// macOS doesn't send proper key events for modifiers, only
|
||||||
|
// state change events. That gets extra confusing for CapsLock
|
||||||
|
// which toggles on each press, but not on release. So pretend
|
||||||
|
// it was a quick press and release of the button.
|
||||||
|
if (isMac() && (code === 'CapsLock')) {
|
||||||
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
||||||
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
||||||
|
stopEvent(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If this is a legacy browser then we'll need to wait for
|
// If this is a legacy browser then we'll need to wait for
|
||||||
// a keypress event as well
|
// a keypress event as well
|
||||||
if (!keysym) {
|
if (!keysym) {
|
||||||
|
@ -200,6 +211,13 @@ Keyboard.prototype = {
|
||||||
|
|
||||||
var code = this._getKeyCode(e);
|
var code = this._getKeyCode(e);
|
||||||
|
|
||||||
|
// See comment in _handleKeyDown()
|
||||||
|
if (isMac() && (code === 'CapsLock')) {
|
||||||
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
||||||
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Do we really think this key is down?
|
// Do we really think this key is down?
|
||||||
if (!(code in this._keyDownList)) {
|
if (!(code in this._keyDownList)) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue