| | |
| | | <script lang="ts"> |
| | | import { onDestroy } from 'svelte' |
| | | import { Call } from '@wailsio/runtime' |
| | | import { t } from '../../lib/i18n' |
| | | import { hotkeyVK } from '../../lib/stores/config' |
| | |
| | | let currentKeyName = $state('Ctrl') |
| | | let isRecording = $state(false) |
| | | let hintText = $state('') |
| | | let activeKeyHandler: ((e: KeyboardEvent) => void) | null = null |
| | | |
| | | const unsub = hotkeyName.subscribe(k => { currentKeyName = k }) |
| | | |
| | | onDestroy(() => { |
| | | unsub() |
| | | clearHotkeyCapture() |
| | | }) |
| | | |
| | | async function startRecordingHotkey() { |
| | | clearHotkeyCapture() |
| | | isRecording = true |
| | | hintText = t('hotkeys.pressAnyKey') |
| | | |
| | |
| | | } catch {} |
| | | })() |
| | | |
| | | document.removeEventListener('keydown', onKey) |
| | | clearHotkeyCapture() |
| | | } |
| | | } |
| | | |
| | | activeKeyHandler = onKey |
| | | document.addEventListener('keydown', onKey) |
| | | } |
| | | |
| | | function clearHotkeyCapture() { |
| | | if (activeKeyHandler) { |
| | | document.removeEventListener('keydown', activeKeyHandler) |
| | | activeKeyHandler = null |
| | | } |
| | | if (isRecording) { |
| | | isRecording = false |
| | | void Call.ByName('voicesnap/services.HotkeyService.StopRecordingHotkey').catch(() => {}) |
| | | } |
| | | } |
| | | |
| | | function mapKeyToVK(e: KeyboardEvent): number { |
| | | // Map browser key codes to Windows VK codes |
| | | switch (e.key) { |