Skip to content

Commit e8ef82e

Browse files
authored
feat(ui) Fix the CapsLock and Shift key for VirtualKeyboard (#779)
* feat(ui) Fix the CapsLock and Shift key for VirtualKeyboard * PR feedback: Default LED state in store
1 parent 5f3dd89 commit e8ef82e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ui/src/components/VirtualKeyboard.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function KeyboardWrapper() {
2525
const keyboardRef = useRef<HTMLDivElement>(null);
2626
const { isAttachedVirtualKeyboardVisible, setAttachedVirtualKeyboardVisibility } =
2727
useUiStore();
28-
const { keysDownState, isVirtualKeyboardEnabled, setVirtualKeyboardEnabled } =
28+
const { keyboardLedState, keysDownState, isVirtualKeyboardEnabled, setVirtualKeyboardEnabled } =
2929
useHidStore();
3030
const { handleKeyPress, executeMacro } = useKeyboard();
3131
const { selectedKeyboard } = useKeyboardLayout();
@@ -46,9 +46,15 @@ function KeyboardWrapper() {
4646
return decodeModifiers(keysDownState.modifier);
4747
}, [keysDownState]);
4848

49+
const isCapsLockActive = useMemo(() => {
50+
return keyboardLedState.caps_lock;
51+
}, [keyboardLedState]);
52+
4953
const mainLayoutName = useMemo(() => {
50-
return isShiftActive ? "shift" : "default";
51-
}, [isShiftActive]);
54+
// if you have the CapsLock "latched", then the shift state is inverted
55+
const effectiveShift = isCapsLockActive ? false === isShiftActive : isShiftActive;
56+
return effectiveShift ? "shift" : "default";
57+
}, [isCapsLockActive, isShiftActive]);
5258

5359
const keyNamesForDownKeys = useMemo(() => {
5460
const activeModifierMask = keysDownState.modifier || 0;

ui/src/hooks/stores.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ export interface HidState {
463463
}
464464

465465
export const useHidStore = create<HidState>(set => ({
466-
keyboardLedState: {} as KeyboardLedState,
466+
keyboardLedState: { num_lock: false, caps_lock: false, scroll_lock: false, compose: false, kana: false, shift: false } as KeyboardLedState,
467467
setKeyboardLedState: (ledState: KeyboardLedState): void => set({ keyboardLedState: ledState }),
468468

469469
keysDownState: { modifier: 0, keys: [0,0,0,0,0,0] } as KeysDownState,

0 commit comments

Comments
 (0)