61 lines
1.3 KiB
Python
61 lines
1.3 KiB
Python
from pynput import keyboard
|
|
import os
|
|
import pynput
|
|
import sys
|
|
import typer
|
|
|
|
ptt_key = 269025026
|
|
|
|
|
|
def unmute():
|
|
print("unmute")
|
|
os.system("pactl set-source-mute @DEFAULT_SOURCE@ false")
|
|
|
|
|
|
def mute():
|
|
print("mute")
|
|
os.system("pactl set-source-mute @DEFAULT_SOURCE@ true")
|
|
|
|
|
|
def on_press(key):
|
|
if hasattr(key, "vk") and key.vk == ptt_key:
|
|
unmute()
|
|
|
|
|
|
def on_release(key):
|
|
if hasattr(key, "vk") and key.vk == ptt_key:
|
|
mute()
|
|
|
|
|
|
def fetch_keycode(key):
|
|
if key == keyboard.Key.esc:
|
|
return False
|
|
if hasattr(key, "vk"):
|
|
print(key.vk)
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
@app.command()
|
|
def get_keycode():
|
|
print("Listending for keycodes, press esc to exit")
|
|
listener = keyboard.Listener(on_press=fetch_keycode)
|
|
listener.start() # start to listen on a separate thread
|
|
listener.join() # remove if main thread is polling self.keys
|
|
|
|
|
|
@app.command()
|
|
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}")
|
|
listener.start() # start to listen on a separate thread
|
|
listener.join() # remove if main thread is polling self.keys
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app()
|