feat(hid): 添加 Consumer Control 多媒体按键和多平台键盘布局

- 新增 Consumer Control HID 支持(播放/暂停、音量控制等)
- 虚拟键盘支持 Windows/Mac/Android 三种布局切换
- 移除键盘 LED 反馈以节省 USB 端点(从 2 减至 1)
- InfoBar 优化:按键名称友好显示,移除未实现的 Num/Scroll 指示器
- 更新 HID 模块文档
This commit is contained in:
mofeng-git
2026-01-02 23:52:12 +08:00
parent ad401cdf1c
commit cb7d9882a2
27 changed files with 888 additions and 262 deletions

View File

@@ -5,15 +5,17 @@ import { ref, onUnmounted } from 'vue'
import {
type HidKeyboardEvent,
type HidMouseEvent,
type HidConsumerEvent,
encodeKeyboardEvent,
encodeMouseEvent,
encodeConsumerEvent,
RESP_OK,
RESP_ERR_HID_UNAVAILABLE,
RESP_ERR_INVALID_MESSAGE,
} from '@/types/hid'
import { buildWsUrl, WS_RECONNECT_DELAY } from '@/types/websocket'
export type { HidKeyboardEvent, HidMouseEvent }
export type { HidKeyboardEvent, HidMouseEvent, HidConsumerEvent }
let wsInstance: WebSocket | null = null
const connected = ref(false)
@@ -213,6 +215,23 @@ function sendMouse(event: HidMouseEvent): Promise<void> {
})
}
// Send consumer control event (multimedia keys)
function sendConsumer(event: HidConsumerEvent): Promise<void> {
return new Promise((resolve, reject) => {
if (!wsInstance || wsInstance.readyState !== WebSocket.OPEN) {
reject(new Error('WebSocket not connected'))
return
}
try {
wsInstance.send(encodeConsumerEvent(event))
resolve()
} catch (err) {
reject(err)
}
})
}
export function useHidWebSocket() {
onUnmounted(() => {
// Don't disconnect on component unmount - WebSocket is shared
@@ -229,6 +248,7 @@ export function useHidWebSocket() {
disconnect,
sendKeyboard,
sendMouse,
sendConsumer,
}
}