Skip to content

Commit 052e026

Browse files
committed
refactor: optimize keyboard keys and refactor keyboard shortcut
1 parent 758449c commit 052e026

20 files changed

Lines changed: 760 additions & 407 deletions

File tree

browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13+
"@radix-ui/react-scroll-area": "^1.2.10",
1314
"antd": "^5.22.2",
1415
"clsx": "^2.1.1",
1516
"i18next": "^24.0.5",

browser/pnpm-lock.yaml

Lines changed: 179 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/src/components/keyboard/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { device } from '@/libs/device';
44
import { Modifiers } from '@/libs/device/keyboard.ts';
55
import { KeyboardCodes } from '@/libs/keyboard';
66

7-
const MAX_SIMULTANEOUS_KEYS = 4;
7+
const MAX_SIMULTANEOUS_KEYS = 6;
88
const ModifierKeys = new Set(['Control', 'Shift', 'Alt', 'Meta']);
99

1010
export const Keyboard = () => {
@@ -44,7 +44,7 @@ export const Keyboard = () => {
4444
}
4545
}
4646

47-
await sendKeyData(event);
47+
await sendKeyData();
4848
}
4949

5050
// release button
@@ -61,7 +61,7 @@ export const Keyboard = () => {
6161
}
6262
}
6363

64-
await sendKeyData(event);
64+
await sendKeyData();
6565
}
6666

6767
// release all keys when page loses focus
@@ -86,11 +86,13 @@ export const Keyboard = () => {
8686
}
8787

8888
// send keyboard data
89-
async function sendKeyData(event: KeyboardEvent) {
90-
const modifiers = Modifiers.getModifiers(event, pressedModifiersRef.current);
89+
async function sendKeyData() {
90+
const modifiers = new Modifiers();
91+
pressedModifiersRef.current.forEach((code) => {
92+
modifiers.setModifier(code);
93+
});
94+
9195
const keys = [
92-
0x00,
93-
0x00,
9496
...Array.from(pressedKeysRef.current),
9597
...new Array(MAX_SIMULTANEOUS_KEYS - pressedKeysRef.current.size).fill(0x00)
9698
];

browser/src/components/menu/keyboard/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import { Popover } from 'antd';
33
import { KeyboardIcon } from 'lucide-react';
44

55
import { Paste } from './paste.tsx';
6+
import { Shortcuts } from './shortcuts';
67
import { VirtualKeyboard } from './virtual-keyboard.tsx';
7-
import { KeyboardShortcutsMenu } from './shortcuts-menu.tsx';
88

99
export const Keyboard = () => {
1010
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
1111

1212
const content = (
13-
<>
13+
<div className="flex flex-col space-y-0.5">
1414
<Paste />
1515
<VirtualKeyboard />
16-
<KeyboardShortcutsMenu />
17-
</>
16+
<Shortcuts />
17+
</div>
1818
);
1919

2020
return (

0 commit comments

Comments
 (0)