Use physical keys+layout for shortcuts
This commit is contained in:
parent
b6cfe0933d
commit
3e31a7405b
5 changed files with 50 additions and 6 deletions
31
ts/services/keyboardLayout.ts
Normal file
31
ts/services/keyboardLayout.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { strictAssert } from '../util/assert';
|
||||
|
||||
type LayoutMapType = { get(code: string): string | undefined };
|
||||
|
||||
let layoutMap: LayoutMapType | undefined;
|
||||
|
||||
export async function initialize(): Promise<void> {
|
||||
strictAssert(layoutMap === undefined, 'keyboardLayout already initialized');
|
||||
|
||||
const experimentalNavigator = (window.navigator as unknown) as {
|
||||
keyboard: { getLayoutMap(): Promise<LayoutMapType> };
|
||||
};
|
||||
|
||||
strictAssert(
|
||||
typeof experimentalNavigator.keyboard?.getLayoutMap === 'function',
|
||||
'No support for getLayoutMap'
|
||||
);
|
||||
|
||||
layoutMap = await experimentalNavigator.keyboard.getLayoutMap();
|
||||
}
|
||||
|
||||
export function lookup({
|
||||
code,
|
||||
key,
|
||||
}: Pick<KeyboardEvent, 'code' | 'key'>): string | undefined {
|
||||
strictAssert(layoutMap !== undefined, 'keyboardLayout not initialized');
|
||||
return layoutMap.get(code) ?? key;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue