Skip to content

Commit

Permalink
通过注册表键值监测是否在录音
Browse files Browse the repository at this point in the history
  • Loading branch information
H1DDENADM1N committed Dec 13, 2024
1 parent fcf733e commit 3ddfbaa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions start_client_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path
from queue import Queue

import keyboard
import win32api
import win32con
import win32gui
Expand All @@ -30,6 +29,7 @@
from qt_material import apply_stylesheet

from config import ClientConfig as Config
from util.check_microphone_usage import is_microphone_in_use
from util.check_process import check_process


Expand All @@ -53,7 +53,7 @@ def update_tooltip_position(self):
x, y = x / scale_x, y / scale_y
# 更新标签的位置和文本
self.move(x + (20 / scale_x), y + (20 / scale_y))
if keyboard.is_pressed(Config.speech_recognition_shortcut):
if is_microphone_in_use():
self.setText(chr(0xF8B1))
self.setVisible(True)
else:
Expand Down Expand Up @@ -648,7 +648,7 @@ def start_client_gui():
["hint_while_recording.exe"], creationflags=subprocess.CREATE_NO_WINDOW
)
app = QApplication(sys.argv)
if Config.hint_while_recording_at_cursor_position and Config.hold_mode:
if Config.hint_while_recording_at_cursor_position:
tooltip = Hint_While_Recording_At_Cursor_Position()
tooltip.show()
apply_stylesheet(
Expand Down
52 changes: 52 additions & 0 deletions util/check_microphone_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import time
import winreg
from pathlib import Path


def read_qword_value(root_key, sub_path, value_name):
try:
reg_key = winreg.OpenKey(root_key, sub_path)
value, reg_type = winreg.QueryValueEx(reg_key, value_name)
if reg_type == winreg.REG_QWORD:
return value
else:
print(f"Value {value_name} is not a QWORD.")
return None
except FileNotFoundError:
print("Registry key or value not found.")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None


def is_microphone_in_use():
current_path = Path().cwd()
sub_path = (
r"Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone\NonPackaged\\"
+ str(current_path).replace("\\", "#")
+ r"#runtime#pythonw_CapsWriter_Client.exe"
)
# print(sub_path)
value_name = "LastUsedTimeStop"

qword_value = read_qword_value(winreg.HKEY_CURRENT_USER, sub_path, value_name)
if qword_value is not None:
# print(f"QWORD value: {qword_value}") # 麦克风 上次访问时间戳
if qword_value == 0:
# print("Microphone is in use.")
return True
else:
return False
else:
# print("Failed to read QWORD value.")
return None


if __name__ == "__main__":
while True:
if is_microphone_in_use():
print("Microphone is in use.")
else:
pass
time.sleep(1)

0 comments on commit 3ddfbaa

Please sign in to comment.