Trema is the more robust method for capital umlauts

This commit is contained in:
Daniel Lorch 2025-05-02 01:32:12 +02:00
parent c3087abe02
commit 962a6f6dfc
3 changed files with 32 additions and 22 deletions

View File

@ -48,34 +48,44 @@ export default function PasteModal() {
try { try {
for (const char of text) { for (const char of text) {
const { key, shift, altRight, space, capsLock } = chars[keyboardLayout][char] ?? {}; const { key, shift, altRight, space, capsLock, trema } = chars[keyboardLayout][char] ?? {};
if (!key) continue; if (!key) continue;
const keyz = [keys[key]]; const keyz = [ keys[key] ];
const modz = [ shift ? modifiers["ShiftLeft"] : 0
| (altRight ? modifiers["AltRight"] : 0) ];
if (space) { if (space) {
keyz.push(keys["Space"]); keyz.push(keys["Space"]);
modz.push(0);
} }
if (capsLock) { if (capsLock) {
keyz.unshift(keys["CapsLock"]); keyz.unshift(keys["CapsLock"]);
modz.unshift(0);
keyz.push(keys["CapsLock"]); keyz.push(keys["CapsLock"]);
modz.push(0);
}
if (trema) {
keyz.unshift(keys["BracketRight"]); // trema ¨
modz.unshift(0)
} }
const modz = shift ? modifiers["ShiftLeft"] : 0 for (const [index, keyy] of keyz.entries()) {
| (altRight ? modifiers["AltRight"] : 0); await new Promise<void>((resolve, reject) => {
send(
await new Promise<void>((resolve, reject) => { "keyboardReport",
send( hidKeyboardPayload([keyy], modz[index]),
"keyboardReport", params => {
hidKeyboardPayload(keyz, modz),
params => {
if ("error" in params) return reject(params.error);
send("keyboardReport", hidKeyboardPayload([], 0), params => {
if ("error" in params) return reject(params.error); if ("error" in params) return reject(params.error);
resolve(); send("keyboardReport", hidKeyboardPayload([], 0), params => {
}); if ("error" in params) return reject(params.error);
}, resolve();
); });
}); },
);
});
}
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@ -9,4 +9,4 @@ export const layouts = {
export const chars = { export const chars = {
"en_US": chars_en_US, "en_US": chars_en_US,
"de_CH": chars_de_CH, "de_CH": chars_de_CH,
} as Record<string, Record<string, { key: string | number; shift?: boolean, altRight?: boolean, space?: boolean, capsLock?: boolean }>>; } as Record<string, Record<string, { key: string | number; shift?: boolean, altRight?: boolean, space?: boolean, capsLock?: boolean, trema?: boolean }>>;

View File

@ -1,5 +1,6 @@
export const chars = { export const chars = {
A: { key: "KeyA", shift: true }, A: { key: "KeyA", shift: true },
"Ä": { key: "KeyA", shift: true, trema: true },
B: { key: "KeyB", shift: true }, B: { key: "KeyB", shift: true },
C: { key: "KeyC", shift: true }, C: { key: "KeyC", shift: true },
D: { key: "KeyD", shift: true }, D: { key: "KeyD", shift: true },
@ -14,12 +15,14 @@ export const chars = {
M: { key: "KeyM", shift: true }, M: { key: "KeyM", shift: true },
N: { key: "KeyN", shift: true }, N: { key: "KeyN", shift: true },
O: { key: "KeyO", shift: true }, O: { key: "KeyO", shift: true },
"Ö": { key: "KeyO", shift: true, trema: true },
P: { key: "KeyP", shift: true }, P: { key: "KeyP", shift: true },
Q: { key: "KeyQ", shift: true }, Q: { key: "KeyQ", shift: true },
R: { key: "KeyR", shift: true }, R: { key: "KeyR", shift: true },
S: { key: "KeyS", shift: true }, S: { key: "KeyS", shift: true },
T: { key: "KeyT", shift: true }, T: { key: "KeyT", shift: true },
U: { key: "KeyU", shift: true }, U: { key: "KeyU", shift: true },
"Ü": { key: "KeyU", shift: true, trema: true },
V: { key: "KeyV", shift: true }, V: { key: "KeyV", shift: true },
W: { key: "KeyW", shift: true }, W: { key: "KeyW", shift: true },
X: { key: "KeyX", shift: true }, X: { key: "KeyX", shift: true },
@ -108,16 +111,13 @@ export const chars = {
"ü": { key: "BracketLeft" }, "ü": { key: "BracketLeft" },
"è": { key: "BracketLeft", shift: true }, "è": { key: "BracketLeft", shift: true },
"[": { key: "BracketLeft", altRight: true }, "[": { key: "BracketLeft", altRight: true },
"Ü": { key: "BracketLeft", capsLock: true },
"!": { key: "BracketRight", shift: true }, "!": { key: "BracketRight", shift: true },
"]": { key: "BracketRight", altRight: true }, "]": { key: "BracketRight", altRight: true },
"ö": { key: "Semicolon" }, "ö": { key: "Semicolon" },
"é": { key: "Semicolon", shift: true }, "é": { key: "Semicolon", shift: true },
"Ö": { key: "Semicolon", capsLock: true },
"ä": { key: "Quote" }, "ä": { key: "Quote" },
"à": { key: "Quote", shift: true }, "à": { key: "Quote", shift: true },
"{": { key: "Quote", altRight: true }, "{": { key: "Quote", altRight: true },
"Ä": { key: "Quote", capsLock: true },
"$": { key: "Backslash" }, "$": { key: "Backslash" },
"£": { key: "Backslash", shift: true }, "£": { key: "Backslash", shift: true },
"}": { key: "Backslash", altRight: true }, "}": { key: "Backslash", altRight: true },
@ -137,4 +137,4 @@ export const chars = {
"\n": { key: "Enter" }, "\n": { key: "Enter" },
Enter: { key: "Enter" }, Enter: { key: "Enter" },
Tab: { key: "Tab" }, Tab: { key: "Tab" },
} as Record<string, { key: string | number; shift?: boolean, altRight?: boolean, space?: boolean, capsLock?: boolean }> } as Record<string, { key: string | number; shift?: boolean, altRight?: boolean, space?: boolean, capsLock?: boolean, trema?: boolean }>