This commit is contained in:
Martin Benonisen 2024-03-09 18:23:54 +01:00
parent 641b69aae7
commit 5c2b424407
Signed by: mbeno
GPG Key ID: 025254EFB372A723

View File

@ -1,18 +1,39 @@
from pynput import keyboard
import os
import pynput
import sys
import subprocess
import typer
import time
ptt_key = 269025026
TALKING = False
def get_desc(keycode):
hex_code = f"{keycode:#0{6}x}"
try:
s = subprocess.check_output(
f"xmodmap -pk | grep '{hex_code}'",
shell=True,
)
return s.decode().split("\t")[1]
except:
return "<unknown key>"
def unmute():
global TALKING
if TALKING:
return
else:
TALKING = True
print("unmute")
os.system("pactl set-source-mute @DEFAULT_SOURCE@ false")
def mute():
global TALKING
TALKING = False
print("mute")
os.system("pactl set-source-mute @DEFAULT_SOURCE@ true")
@ -31,7 +52,7 @@ def fetch_keycode(key):
if key == keyboard.Key.esc:
return False
if hasattr(key, "vk"):
print(key.vk)
print(f"Keycode {get_desc(key.vk)}")
app = typer.Typer()
@ -49,9 +70,12 @@ def get_keycode():
def ptt(keycode=None):
global ptt_key
if keycode:
ptt_key = int(keycode)
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
print(f"Starting push to talk using keycode: {keycode}")
ptt_key = int(keycode, 16)
listener = keyboard.Listener(
on_press=on_press,
on_release=on_release,
)
print(f"Binding PTT key: {get_desc(ptt_key)}")
listener.start() # start to listen on a separate thread
listener.join() # remove if main thread is polling self.keys