-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomute.py
executable file
·49 lines (42 loc) · 1.53 KB
/
automute.py
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
#!/usr/bin/env python3
# keyboard automute for linux
# makes you less of an ass while using your MECHANICAL KEYBOARD in zoom/teams/whatever meetings
#
# usage:
# 1. build the kernel module in keycounts, then insmod keycounts.ko
# 2. run this script as root
# Note, you may need to modify the mute() and unmute() functions to actually mute and unmute
# on your system
# YMMV
# if you like this, buy me a beer or support your local charity
import sys,os,time
keycount = 0
lastkeyat=0
def mute():
#os.system("pacmd list-sources | grep -oP 'index: \d+' | awk '{ print $2 }' | xargs -I{} pactl set-source-mute {} on")
os.system("amixer set Capture toggle >/dev/null 2>&1")
def unmute():
#os.system("pacmd list-sources | grep -oP 'index: \d+' | awk '{ print $2 }' | xargs -I{} pactl set-source-mute {} off")
os.system("amixer set Capture toggle >/dev/null 2>&1")
muted=False
try:
while True:
newcount = int(open('/sys/kernel/debug/keypresscount','r').read().strip())
time.sleep(.05)
if newcount == 0:
keycount = newcount
continue
if newcount != keycount: # new keypresses since last time
lastkeyat=time.time()
keycount = newcount
if not muted:
print("c=%4d mute"%newcount)
mute()
muted = True
if time.time()-lastkeyat > .25 and muted:
print("c=%4d unmute"%keycount)
muted = False
unmute()
time.sleep(.05)
except KeyboardInterrupt:
sys.exit(0)