detect single keypresses

This commit is contained in:
sawka 2024-08-28 18:42:04 -07:00
parent 56a930c1dc
commit bfab5e4223

View File

@ -1,6 +1,8 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import * as util from "./util";
const KeyTypeCodeRegex = /c{(.*)}/;
const KeyTypeKey = "key";
const KeyTypeCode = "code";
@ -76,6 +78,13 @@ function notMod(keyPressMod: boolean, eventMod: boolean) {
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 {
let keyPress = parseKeyDescription(keyDescription);
if (!keyPress.mods.Alt && notMod(keyPress.mods.Option, event.option)) {
@ -155,6 +164,7 @@ export {
adaptFromElectronKeyEvent,
adaptFromReactOrNativeKeyEvent,
checkKeyPressed,
isCharacterKeyEvent,
keydownWrapper,
parseKeyDescription,
setKeyUtilPlatform,