On Linux, I just tested that if you have a Mozilla Firefox window running on X (I tested on XWayland but it should work just as well on X11) with the Discord tab in view, you can use your desktop's/compositor global keyboard shortcut functionality to call xdotool to send a keyup/keydown event without focusing the window, like this:
xdotool search --name 'Discord.*— Mozilla Firefox' keydown F9
xdotool search --name 'Discord.*— Mozilla Firefox' keyup F9
I configured web Discord to use F9 as the push to talk button since it seemingly doesn't conflict with anything in Firefox, but you can then bind it to any key or mouse button on your global keyboard shortcut settings.
According to some people on StackExchange (I didn't test myself) this doesn't work if you're using Discord on Chromium-based browsers, which seem to reject xdotool events unless the window is focused (which xdotool can do for you, but doesn't work for the PTT usecase). Of course, this doesn't work on Firefox when running native Wayland windows because xdotool is X-only, and ydotool doesn't work either because it emulates a virtual device which would mean you still need to focus the window.
> It seems like a WebExtension using dispatchEvent could solve both these issues.
Great idea! Couldn't find anything any pre-existing project like that from a quick web search and tbh I have enough side projects as it is, but that would indeed solve the issue for both.
According to some people on StackExchange (I didn't test myself) this doesn't work if you're using Discord on Chromium-based browsers, which seem to reject xdotool events unless the window is focused (which xdotool can do for you, but doesn't work for the PTT usecase). Of course, this doesn't work on Firefox when running native Wayland windows because xdotool is X-only, and ydotool doesn't work either because it emulates a virtual device which would mean you still need to focus the window.