-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicrophone_state_monitor.pyw
More file actions
49 lines (40 loc) · 1.36 KB
/
Copy pathmicrophone_state_monitor.pyw
File metadata and controls
49 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import natlink
import subprocess
import win32gui
def microphone_state_autohotkey(*args):
autohotkey.run('Dragon Microphone State', *args)
last_mic_state = None
def natlink_change(user_or_mic, changed_to):
global last_mic_state
if user_or_mic != 'mic':
return
if changed_to == 'sleeping': # makes comparison easier
changed_to = 'off'
if last_mic_state == changed_to:
return # flapping between off/sleeping at startup can trigger a race
last_mic_state = changed_to
microphone_state_autohotkey(changed_to)
def destroy_window():
microphone_state_autohotkey()
if __name__ == '__main__':
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
import autohotkey
import sys
should_start_monitor = len(sys.argv) == 1
if should_start_monitor:
logging.basicConfig(filename='microphone_state_monitor.log',
format='%(asctime)s %(levelname)-5s %(name)s: %(message)s',
datefmt='%m/%d %H:%M:%S',
level=logging.DEBUG)
try:
if should_start_monitor:
natlink.natConnect(True)
logging.debug('getMicState at startup: ' + natlink.getMicState())
natlink.setChangeCallback(natlink_change)
win32gui.PumpMessages()
else:
destroy_window()
except:
logging.exception('')