diff --git a/frontend/util/keyutil.ts b/frontend/util/keyutil.ts index a718bc909..df2af40be 100644 --- a/frontend/util/keyutil.ts +++ b/frontend/util/keyutil.ts @@ -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,