2016-04-05 20:14:11 +08:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-12-01 18:30:49 +08:00
|
|
|
Copyright 2017 New Vector Ltd
|
2019-12-17 01:14:03 +08:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2016-04-05 20:14:11 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-09-30 23:04:06 +08:00
|
|
|
export const Key = {
|
|
|
|
HOME: "Home",
|
2019-10-10 02:59:11 +08:00
|
|
|
END: "End",
|
2019-09-30 23:04:06 +08:00
|
|
|
PAGE_UP: "PageUp",
|
|
|
|
PAGE_DOWN: "PageDown",
|
2019-10-04 18:47:33 +08:00
|
|
|
BACKSPACE: "Backspace",
|
2020-03-26 15:37:46 +08:00
|
|
|
DELETE: "Delete",
|
2019-10-10 02:59:11 +08:00
|
|
|
ARROW_UP: "ArrowUp",
|
|
|
|
ARROW_DOWN: "ArrowDown",
|
2019-10-17 22:53:39 +08:00
|
|
|
ARROW_LEFT: "ArrowLeft",
|
|
|
|
ARROW_RIGHT: "ArrowRight",
|
2019-10-10 02:59:11 +08:00
|
|
|
TAB: "Tab",
|
|
|
|
ESCAPE: "Escape",
|
2019-10-04 18:47:33 +08:00
|
|
|
ENTER: "Enter",
|
2019-10-10 02:59:11 +08:00
|
|
|
ALT: "Alt",
|
|
|
|
CONTROL: "Control",
|
|
|
|
META: "Meta",
|
|
|
|
SHIFT: "Shift",
|
2019-12-02 18:01:08 +08:00
|
|
|
CONTEXT_MENU: "ContextMenu",
|
2019-09-30 23:04:06 +08:00
|
|
|
|
2019-12-17 01:14:03 +08:00
|
|
|
COMMA: ",",
|
2020-03-20 08:18:24 +08:00
|
|
|
PERIOD: ".",
|
2019-10-10 02:59:11 +08:00
|
|
|
LESS_THAN: "<",
|
|
|
|
GREATER_THAN: ">",
|
|
|
|
BACKTICK: "`",
|
|
|
|
SPACE: " ",
|
2020-03-19 00:40:21 +08:00
|
|
|
SLASH: "/",
|
2020-04-12 01:57:59 +08:00
|
|
|
SQUARE_BRACKET_LEFT: "[",
|
|
|
|
SQUARE_BRACKET_RIGHT: "]",
|
2019-12-17 01:14:03 +08:00
|
|
|
A: "a",
|
2019-10-10 02:59:11 +08:00
|
|
|
B: "b",
|
2019-12-17 01:14:03 +08:00
|
|
|
C: "c",
|
|
|
|
D: "d",
|
|
|
|
E: "e",
|
|
|
|
F: "f",
|
|
|
|
G: "g",
|
|
|
|
H: "h",
|
2019-10-10 02:59:11 +08:00
|
|
|
I: "i",
|
2019-12-17 01:14:03 +08:00
|
|
|
J: "j",
|
2019-09-30 23:04:06 +08:00
|
|
|
K: "k",
|
2019-12-17 01:14:03 +08:00
|
|
|
L: "l",
|
|
|
|
M: "m",
|
|
|
|
N: "n",
|
|
|
|
O: "o",
|
|
|
|
P: "p",
|
|
|
|
Q: "q",
|
|
|
|
R: "r",
|
|
|
|
S: "s",
|
|
|
|
T: "t",
|
|
|
|
U: "u",
|
|
|
|
V: "v",
|
|
|
|
W: "w",
|
|
|
|
X: "x",
|
2019-10-10 02:59:11 +08:00
|
|
|
Y: "y",
|
|
|
|
Z: "z",
|
2016-04-05 20:14:11 +08:00
|
|
|
};
|
2017-12-01 18:30:49 +08:00
|
|
|
|
2020-03-19 00:40:21 +08:00
|
|
|
export const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
|
|
|
|
2017-12-01 18:44:00 +08:00
|
|
|
export function isOnlyCtrlOrCmdKeyEvent(ev) {
|
2017-12-01 18:30:49 +08:00
|
|
|
if (isMac) {
|
|
|
|
return ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey;
|
|
|
|
} else {
|
|
|
|
return ev.ctrlKey && !ev.altKey && !ev.metaKey && !ev.shiftKey;
|
|
|
|
}
|
|
|
|
}
|
2018-01-03 19:39:15 +08:00
|
|
|
|
2018-01-04 20:06:13 +08:00
|
|
|
export function isOnlyCtrlOrCmdIgnoreShiftKeyEvent(ev) {
|
2018-01-03 19:39:15 +08:00
|
|
|
if (isMac) {
|
2018-01-04 20:06:13 +08:00
|
|
|
return ev.metaKey && !ev.altKey && !ev.ctrlKey;
|
2018-01-03 19:39:15 +08:00
|
|
|
} else {
|
2018-01-04 20:06:13 +08:00
|
|
|
return ev.ctrlKey && !ev.altKey && !ev.metaKey;
|
2018-01-03 19:39:15 +08:00
|
|
|
}
|
|
|
|
}
|