#!/bin/bash

# Replace 'F12' with your configured push-to-talk key
PUSH_TO_TALK_KEY="F7"

# Get the window ID of the Discord application
DISCORD_WINDOW=$(xdotool search --onlyvisible --class "discord")

# Loop to keep the script running
while true; do
    # Check if the Discord window is active
    if xdotool getactivewindow getwindowname | grep -q "Discord"; then
        # Check if the push-to-talk key is pressed
        if xinput --query-state "AT Translated Set 2 keyboard" | grep -q "key$$68$$=down"; then
            # Simulate key press
            xdotool keydown $PUSH_TO_TALK_KEY
            sleep 0.1  # Hold the key down for a short duration
            xdotool keyup $PUSH_TO_TALK_KEY
        fi
    fi
    sleep 0.1  # Check every 100ms
done
