mirror of
https://github.com/ayangweb/BongoCat.git
synced 2026-03-12 17:51:48 +08:00
fix: 修复 Windows 按键未正确记录的问题 (#575)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { CursorPoint } from '@/utils/monitor'
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import { isEqual, mapValues } from 'es-toolkit'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -10,7 +11,6 @@ import { useModel } from './useModel'
|
||||
import { useTauriListen } from './useTauriListen'
|
||||
|
||||
import { useModelStore } from '@/stores/model'
|
||||
import { isWindows } from '@/utils/platform'
|
||||
|
||||
interface MouseButtonEvent {
|
||||
kind: 'MousePress' | 'MouseRelease'
|
||||
@@ -32,13 +32,14 @@ type DeviceEvent = MouseButtonEvent | MouseMoveEvent | KeyboardEvent
|
||||
export function useDevice() {
|
||||
const modelStore = useModelStore()
|
||||
const lastCursorPoint = ref<CursorPoint>({ x: 0, y: 0 })
|
||||
const releaseTimers = new Map<string, NodeJS.Timeout>()
|
||||
const { handlePress, handleRelease, handleMouseChange, handleMouseMove } = useModel()
|
||||
|
||||
const startListening = () => {
|
||||
invoke(INVOKE_KEY.START_DEVICE_LISTENING)
|
||||
}
|
||||
|
||||
const debouncedRelease = useDebounceFn(handleRelease, 100)
|
||||
|
||||
const getSupportedKey = (key: string) => {
|
||||
let nextKey = key
|
||||
|
||||
@@ -58,20 +59,6 @@ export function useDevice() {
|
||||
return nextKey
|
||||
}
|
||||
|
||||
const handleScheduleRelease = (key: string, delay = 500) => {
|
||||
if (releaseTimers.has(key)) {
|
||||
clearTimeout(releaseTimers.get(key))
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
handleRelease(key)
|
||||
|
||||
releaseTimers.delete(key)
|
||||
}, delay)
|
||||
|
||||
releaseTimers.set(key, timer)
|
||||
}
|
||||
|
||||
const processMouseMove = (point: CursorPoint) => {
|
||||
const roundedValue = mapValues(point, Math.round)
|
||||
|
||||
@@ -93,14 +80,10 @@ export function useDevice() {
|
||||
if (nextValue === 'CapsLock') {
|
||||
handlePress(nextValue)
|
||||
|
||||
return handleScheduleRelease(nextValue, 100)
|
||||
return debouncedRelease(nextValue)
|
||||
}
|
||||
|
||||
if (kind === 'KeyboardPress') {
|
||||
if (isWindows) {
|
||||
handleScheduleRelease(nextValue)
|
||||
}
|
||||
|
||||
return handlePress(nextValue)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user