From cec6e0f8de69f83300edc2b41effd75cd0cdf702 Mon Sep 17 00:00:00 2001 From: Martin Benonisen Date: Sat, 9 Mar 2024 17:18:04 +0100 Subject: [PATCH] lol --- pttplz.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pttplz.py diff --git a/pttplz.py b/pttplz.py new file mode 100644 index 0000000..9db4143 --- /dev/null +++ b/pttplz.py @@ -0,0 +1,60 @@ +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()