Skip to content

Commit 2ec061b

Browse files
authored
feat(Keyboard): Hide Pressed Keys (#518)
1 parent 7e64a52 commit 2ec061b

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

ui/src/components/InfoBar.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function InfoBar() {
2828
const rpcDataChannel = useRTCStore(state => state.rpcDataChannel);
2929

3030
const settings = useSettingsStore();
31+
const showPressedKeys = useSettingsStore(state => state.showPressedKeys);
3132

3233
useEffect(() => {
3334
if (!rpcDataChannel) return;
@@ -97,19 +98,21 @@ export default function InfoBar() {
9798
</div>
9899
)}
99100

100-
<div className="flex items-center gap-x-1">
101-
<span className="text-xs font-semibold">Keys:</span>
102-
<h2 className="text-xs">
103-
{[
104-
...activeKeys.map(
105-
x => Object.entries(keys).filter(y => y[1] === x)[0][0],
106-
),
107-
activeModifiers.map(
108-
x => Object.entries(modifiers).filter(y => y[1] === x)[0][0],
109-
),
110-
].join(", ")}
111-
</h2>
112-
</div>
101+
{showPressedKeys && (
102+
<div className="flex items-center gap-x-1">
103+
<span className="text-xs font-semibold">Keys:</span>
104+
<h2 className="text-xs">
105+
{[
106+
...activeKeys.map(
107+
x => Object.entries(keys).filter(y => y[1] === x)[0][0],
108+
),
109+
activeModifiers.map(
110+
x => Object.entries(modifiers).filter(y => y[1] === x)[0][0],
111+
),
112+
].join(", ")}
113+
</h2>
114+
</div>
115+
)}
113116
</div>
114117
</div>
115118
<div className="flex items-center divide-x first:divide-l divide-slate-800/20 dark:divide-slate-300/20">

ui/src/hooks/stores.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ interface SettingsState {
310310

311311
keyboardLedSync: KeyboardLedSync;
312312
setKeyboardLedSync: (sync: KeyboardLedSync) => void;
313+
314+
showPressedKeys: boolean;
315+
setShowPressedKeys: (show: boolean) => void;
313316
}
314317

315318
export const useSettingsStore = create(
@@ -344,6 +347,9 @@ export const useSettingsStore = create(
344347

345348
keyboardLedSync: "auto",
346349
setKeyboardLedSync: sync => set({ keyboardLedSync: sync }),
350+
351+
showPressedKeys: true,
352+
setShowPressedKeys: show => set({ showPressedKeys: show }),
347353
}),
348354
{
349355
name: "settings",

ui/src/routes/devices.$id.settings.keyboard.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useJsonRpc } from "@/hooks/useJsonRpc";
55
import notifications from "@/notifications";
66
import { SettingsPageHeader } from "@components/SettingsPageheader";
77
import { layouts } from "@/keyboardLayouts";
8+
import { Checkbox } from "@/components/Checkbox";
89

910
import { SelectMenuBasic } from "../components/SelectMenuBasic";
1011

@@ -13,12 +14,16 @@ import { SettingsItem } from "./devices.$id.settings";
1314
export default function SettingsKeyboardRoute() {
1415
const keyboardLayout = useSettingsStore(state => state.keyboardLayout);
1516
const keyboardLedSync = useSettingsStore(state => state.keyboardLedSync);
17+
const showPressedKeys = useSettingsStore(state => state.showPressedKeys);
1618
const setKeyboardLayout = useSettingsStore(
1719
state => state.setKeyboardLayout,
1820
);
1921
const setKeyboardLedSync = useSettingsStore(
2022
state => state.setKeyboardLedSync,
2123
);
24+
const setShowPressedKeys = useSettingsStore(
25+
state => state.setShowPressedKeys,
26+
);
2227

2328
// this ensures we always get the original en-US if it hasn't been set yet
2429
const safeKeyboardLayout = useMemo(() => {
@@ -102,6 +107,18 @@ export default function SettingsKeyboardRoute() {
102107
/>
103108
</SettingsItem>
104109
</div>
110+
111+
<div className="space-y-4">
112+
<SettingsItem
113+
title="Show Pressed Keys"
114+
description="Display currently pressed keys in the status bar"
115+
>
116+
<Checkbox
117+
checked={showPressedKeys}
118+
onChange={e => setShowPressedKeys(e.target.checked)}
119+
/>
120+
</SettingsItem>
121+
</div>
105122
</div>
106123
);
107124
}

0 commit comments

Comments
 (0)