fix: CapsLock 复位后忽略重复 Activated 信号

长按阈值触发 CapsLock 复位时设置 capsResetDone_ 标志,
松开前忽略任何重复的 Activated 信号,防止状态混乱。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Alvin Young 2026-06-11 14:25:41 +08:00
parent 1bb0d3895b
commit 74212ff564
2 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,7 @@ VoiceInputService::VoiceInputService(ConfigManager* configManager,
// 长按超时仍未松开 → 确认为长按录音
if (!longPressDetected_) {
longPressDetected_ = true;
capsResetDone_ = true;
// 立即复位 CapsLock不等用户松开
simulateCapsLock();
emit statusChanged("正在录音...");
@ -113,12 +114,19 @@ void VoiceInputService::stop() {
running_ = false;
recording_ = false;
longPressDetected_ = false;
capsResetDone_ = false;
audioBuffer_.clear();
LOG_INFO(kTag, "语音输入服务已停止");
}
void VoiceInputService::onHotkeyActivated() {
// CapsLock 已复位,用户仍按住键 → 忽略重复触发
if (capsResetDone_) {
LOG_DEBUG(kTag, "忽略重复的 ActivatedCapsLock 已复位,等待松开)");
return;
}
LOG_DEBUG(kTag, "快捷键激活(按下)");
recording_ = true;
longPressDetected_ = false;
@ -157,6 +165,7 @@ void VoiceInputService::onHotkeyDeactivated() {
}
longPressDetected_ = false;
capsResetDone_ = false;
}
void VoiceInputService::onAudioData(const std::vector<float>& samples, int sampleRate) {

View File

@ -67,6 +67,7 @@ private:
bool running_ = false;
bool recording_ = false;
bool longPressDetected_ = false;
bool capsResetDone_ = false; // CapsLock 复位后忽略重复 Activated
int longPressThreshold_ = 1000;
std::vector<float> audioBuffer_;