plz
This commit is contained in:
parent
641b69aae7
commit
5c2b424407
@ -1,18 +1,39 @@
|
|||||||
from pynput import keyboard
|
from pynput import keyboard
|
||||||
import os
|
import os
|
||||||
import pynput
|
import subprocess
|
||||||
import sys
|
|
||||||
import typer
|
import typer
|
||||||
|
import time
|
||||||
|
|
||||||
ptt_key = 269025026
|
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():
|
def unmute():
|
||||||
|
global TALKING
|
||||||
|
if TALKING:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
TALKING = True
|
||||||
|
|
||||||
print("unmute")
|
print("unmute")
|
||||||
os.system("pactl set-source-mute @DEFAULT_SOURCE@ false")
|
os.system("pactl set-source-mute @DEFAULT_SOURCE@ false")
|
||||||
|
|
||||||
|
|
||||||
def mute():
|
def mute():
|
||||||
|
global TALKING
|
||||||
|
TALKING = False
|
||||||
print("mute")
|
print("mute")
|
||||||
os.system("pactl set-source-mute @DEFAULT_SOURCE@ true")
|
os.system("pactl set-source-mute @DEFAULT_SOURCE@ true")
|
||||||
|
|
||||||
@ -31,7 +52,7 @@ def fetch_keycode(key):
|
|||||||
if key == keyboard.Key.esc:
|
if key == keyboard.Key.esc:
|
||||||
return False
|
return False
|
||||||
if hasattr(key, "vk"):
|
if hasattr(key, "vk"):
|
||||||
print(key.vk)
|
print(f"Keycode {get_desc(key.vk)}")
|
||||||
|
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
@ -49,9 +70,12 @@ def get_keycode():
|
|||||||
def ptt(keycode=None):
|
def ptt(keycode=None):
|
||||||
global ptt_key
|
global ptt_key
|
||||||
if keycode:
|
if keycode:
|
||||||
ptt_key = int(keycode)
|
ptt_key = int(keycode, 16)
|
||||||
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
|
listener = keyboard.Listener(
|
||||||
print(f"Starting push to talk using keycode: {keycode}")
|
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.start() # start to listen on a separate thread
|
||||||
listener.join() # remove if main thread is polling self.keys
|
listener.join() # remove if main thread is polling self.keys
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user