mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
detect single keypresses
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2024, Command Line Inc.
|
// Copyright 2024, Command Line Inc.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import * as util from "./util";
|
||||||
|
|
||||||
const KeyTypeCodeRegex = /c{(.*)}/;
|
const KeyTypeCodeRegex = /c{(.*)}/;
|
||||||
const KeyTypeKey = "key";
|
const KeyTypeKey = "key";
|
||||||
const KeyTypeCode = "code";
|
const KeyTypeCode = "code";
|
||||||
@@ -76,6 +78,13 @@ function notMod(keyPressMod: boolean, eventMod: boolean) {
|
|||||||
return (keyPressMod && !eventMod) || (eventMod && !keyPressMod);
|
return (keyPressMod && !eventMod) || (eventMod && !keyPressMod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isCharacterKeyEvent(event: WaveKeyboardEvent): boolean {
|
||||||
|
if (event.alt || event.meta || event.control) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return util.countGraphemes(event.key) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): boolean {
|
function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): boolean {
|
||||||
let keyPress = parseKeyDescription(keyDescription);
|
let keyPress = parseKeyDescription(keyDescription);
|
||||||
if (!keyPress.mods.Alt && notMod(keyPress.mods.Option, event.option)) {
|
if (!keyPress.mods.Alt && notMod(keyPress.mods.Option, event.option)) {
|
||||||
@@ -155,6 +164,7 @@ export {
|
|||||||
adaptFromElectronKeyEvent,
|
adaptFromElectronKeyEvent,
|
||||||
adaptFromReactOrNativeKeyEvent,
|
adaptFromReactOrNativeKeyEvent,
|
||||||
checkKeyPressed,
|
checkKeyPressed,
|
||||||
|
isCharacterKeyEvent,
|
||||||
keydownWrapper,
|
keydownWrapper,
|
||||||
parseKeyDescription,
|
parseKeyDescription,
|
||||||
setKeyUtilPlatform,
|
setKeyUtilPlatform,
|
||||||
|
|||||||
Reference in New Issue
Block a user