From a667aefc961824be4a019d8cf7f49ec8c9334d34 Mon Sep 17 00:00:00 2001 From: Siyuan Miao Date: Wed, 10 Sep 2025 23:48:26 +0200 Subject: [PATCH] allow user to override delay --- ui/src/components/popovers/PasteModal.tsx | 39 ++++++++++++++++++++--- ui/src/hooks/useKeyboard.ts | 2 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ui/src/components/popovers/PasteModal.tsx b/ui/src/components/popovers/PasteModal.tsx index 1f5f6403..3466b199 100644 --- a/ui/src/components/popovers/PasteModal.tsx +++ b/ui/src/components/popovers/PasteModal.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { LuCornerDownLeft } from "react-icons/lu"; import { ExclamationCircleIcon } from "@heroicons/react/16/solid"; import { useClose } from "@headlessui/react"; @@ -12,6 +12,7 @@ import { useHidStore, useSettingsStore, useUiStore } from "@/hooks/stores"; import useKeyboard from "@/hooks/useKeyboard"; import useKeyboardLayout from "@/hooks/useKeyboardLayout"; import notifications from "@/notifications"; +import { InputFieldWithLabel } from "@components/InputField"; export default function PasteModal() { const TextAreaRef = useRef(null); @@ -22,6 +23,13 @@ export default function PasteModal() { const { executeMacro, cancelExecuteMacro } = useKeyboard(); const [invalidChars, setInvalidChars] = useState([]); + const [delayValue, setDelayValue] = useState(100); + const delay = useMemo(() => { + if (delayValue < 50 || delayValue > 65534) { + return 100; + } + return delayValue; + }, [delayValue]); const close = useClose(); const { setKeyboardLayout } = useSettingsStore(); @@ -68,7 +76,7 @@ export default function PasteModal() { macroSteps.push({ keys: [String(accentKey.key)], modifiers: accentModifiers.length > 0 ? accentModifiers : null, - delay: 100, + delay, }); } @@ -80,12 +88,12 @@ export default function PasteModal() { macroSteps.push({ keys: [String(key)], modifiers: modifiers.length > 0 ? modifiers : null, - delay: 100, + delay }); // if what was requested was a dead key, we need to send an unmodified space to emit // just the accent character - if (deadKey) macroSteps.push({ keys: ["Space"], modifiers: null, delay: 100 }); + if (deadKey) macroSteps.push({ keys: ["Space"], modifiers: null, delay }); } if (macroSteps.length > 0) { @@ -95,7 +103,7 @@ export default function PasteModal() { console.error("Failed to paste text:", error); notifications.error("Failed to paste text"); } - }, [selectedKeyboard, executeMacro]); + }, [selectedKeyboard, executeMacro, delay]); useEffect(() => { if (TextAreaRef.current) { @@ -168,6 +176,27 @@ export default function PasteModal() { )} +
+ { + setDelayValue(parseInt(e.target.value, 10)); + }} + /> + {delayValue < 50 || delayValue > 65534 && ( +
+ + + Delay must be between 50 and 65534 + +
+ )} +

Sending text using keyboard layout: {selectedKeyboard.isoCode}- diff --git a/ui/src/hooks/useKeyboard.ts b/ui/src/hooks/useKeyboard.ts index 56c108e6..5c660805 100644 --- a/ui/src/hooks/useKeyboard.ts +++ b/ui/src/hooks/useKeyboard.ts @@ -117,7 +117,7 @@ export default function useKeyboard() { // If the step has keys and/or modifiers, press them and hold for the delay if (keyValues.length > 0 || modifierMask > 0) { macro.push({ keys: keyValues, modifier: modifierMask, delay: 20 }); - macro.push({ ...MACRO_RESET_KEYBOARD_STATE, delay: 100 }); + macro.push({ ...MACRO_RESET_KEYBOARD_STATE, delay: step.delay || 100 }); } }