When websocket is processing messages, the keyup signal will take effect. The logs and code are as follows:
if (process.platform !== "darwin") {
const RIGHT_ALT_KEYCODE = 3640;
let holding = false; // 是否正按住
if (!iohook.listenerCount('keydown')) {
iohook.on('keydown', (evt) => {
// 建议只判断 RIGHT_ALT 的 keycode
if (evt.keycode === RIGHT_ALT_KEYCODE && !holding) {
console.log("keydown keyboardStatus holding: ", keyboardStatus, holding);
holding = true;
if (keyboardStatus.recordVoice.disabled) return;
emitter.emit("recordVoice", "recordHold", true);
}
});
iohook.on('keyup', (evt) => {
if (evt.keycode === RIGHT_ALT_KEYCODE && holding) {
console.log("keyup keyboardStatus holding: ", keyboardStatus, holding);
holding = false;
emitter.emit("recordVoice", "recordHold", false);
}
});
iohook.start();
}
}
log
keydown keyboardStatus: { recordVoice: { disabled: false } }
[16:58:00.599 ]: record status { mode: 'hold', running: false }
[16:58:00.601 ]: start
[16:58:00.764 ]: getEnv NODE_ENV development false
[16:58:00.812 (ws:asr)]: connected
[16:58:00.813 ]: call connect
[16:58:00.814 (ws:asr)]: send config
[16:58:00.815 (ws:asr)]: send instruction
[16:58:00.816 ]: wait start instruction 2b0e0156-0835-4a2e-86e7-05d3bf82da61
[16:58:00.824 (ws:asr)]: data:
[16:58:00.825 (ws:asr)]: dataJson:
[16:58:00.826 (ws:asr)]: data:
[16:58:00.827 (ws:asr)]: dataJson:
[16:58:00.845 ]: wait end instruction 2b0e0156-0835-4a2e-86e7-05d3bf82da61
[16:58:02.134 (ws:asr)]: send audio_frame
[16:58:02.155 (ws:asr)]: data:
[16:58:02.156 (ws:asr)]: dataJson:
[16:58:03.213 (ws:asr)]: send audio_frame
[16:58:03.227 (ws:asr)]: data:
[16:58:03.228 (ws:asr)]: dataJson:
[16:58:03.612 (ws:asr)]: data:
[16:58:03.613 (ws:asr)]: dataJson:
[16:58:04.293 (ws:asr)]: send audio_frame
[16:58:04.305 (ws:asr)]: data:
[16:58:04.306 (ws:asr)]: dataJson:
[16:58:05.372 (ws:asr)]: send audio_frame
[16:58:05.387 (ws:asr)]: data:
[16:58:05.388 (ws:asr)]: dataJson:
[16:58:05.692 (ws:asr)]: data:
[16:58:05.693 (ws:asr)]: dataJson:
[16:58:06.453 (ws:asr)]: send audio_frame
[16:58:06.465 (ws:asr)]: data:
[16:58:06.466 (ws:asr)]: dataJson:
[16:58:06.801 (ws:asr)]: data:
[16:58:06.802 (ws:asr)]: dataJson:
[16:58:07.534 (ws:asr)]: send audio_frame
[16:58:07.546 (ws:asr)]: data:
[16:58:07.547 (ws:asr)]: dataJson:
[16:58:08.613 (ws:asr)]: send audio_frame
[16:58:08.626 (ws:asr)]: data:
[16:58:08.627 (ws:asr)]: dataJson:
[16:58:09.694 (ws:asr)]: send audio_frame
[16:58:09.706 (ws:asr)]: data:
[16:58:09.706 (ws:asr)]: dataJson:
[16:58:10.773 (ws:asr)]: send audio_frame
[16:58:10.786 (ws:asr)]: data:
[16:58:10.787 (ws:asr)]: dataJson:
[16:58:11.854 (ws:asr)]: send audio_frame
[16:58:11.866 (ws:asr)]: data:
[16:58:11.867 (ws:asr)]: dataJson:
[16:58:12.933 (ws:asr)]: send audio_frame
[16:58:12.945 (ws:asr)]: data:
[16:58:12.946 (ws:asr)]: dataJson:
[16:58:14.013 (ws:asr)]: send audio_frame
[16:58:14.026 (ws:asr)]: data:
[16:58:14.027 (ws:asr)]: dataJson:
[16:58:15.093 (ws:asr)]: send audio_frame
[16:58:15.106 (ws:asr)]: data:
[16:58:15.107 (ws:asr)]: dataJson:
[16:58:16.173 (ws:asr)]: send audio_frame
[16:58:16.186 (ws:asr)]: data:
[16:58:16.187 (ws:asr)]: dataJson:
[16:58:17.254 (ws:asr)]: send audio_frame
[16:58:17.266 (ws:asr)]: data:
[16:58:17.267 (ws:asr)]: dataJson:
[16:58:18.333 (ws:asr)]: send audio_frame
I would like to ask about the reason. Thank you very much.
When websocket is processing messages, the keyup signal will take effect. The logs and code are as follows:
log
I would like to ask about the reason. Thank you very much.