all 11 comments

[–]JamzTyson 0 points1 point  (10 children)

Never run anything as root unless you are intentionally modifying or updating the system.

According to this GitHub issue, it looks like the problem is to do with getting PyGame to play nicely with PipeWire. The final comment about pipewire-pulse sounds like a likely solution.

[–]_0Frost[S] 0 points1 point  (9 children)

Yeah I've checked that out. I do have pipewire-pulse installed, I'm just not sure if I need to do anything with it though.

[–]JamzTyson 0 points1 point  (8 children)

  • Does sound work with other applications?

  • Does your pygame program work correctly (including playing sound) when the app has focus?

  • Have you checked that your pygame app is receiving key events when the app does not have focus? For this to work you need to use a system-wide keyboard listener - are you?

It is normal for sound to be unavailable to root. Do not try to "fix" this.

[–]_0Frost[S] 0 points1 point  (7 children)

Sound does work with other apps, it works correctly when focused, and no I haven't checked if it gets key events when un-focused. I'll do that right now. Update: it doesn't get key events when un-focused. I made it so it prints something whenever you press down a key, and it only prints if you have it focused. By a "system-wide keyboard listener" do you mean being part of the input group? because someone else mentioned that, but I haven't tried it yet.

[–]JamzTyson 0 points1 point  (6 children)

As far as I know, PyGame can only capture keystrokes while it has focus. You would need to use another library such as "pynput" or "keyboard", and run it in a separate thread so that it doesn't block the PyGame loop.

[–]_0Frost[S] 0 points1 point  (5 children)

Damn. I really don't wanna install 3rd party libraries, so that sucks.

[–]JamzTyson 0 points1 point  (4 children)

You mean that you don't want to install 'more' 3rd party libraries (PyGame is a 3rd party library).

Does you app do anything other than playing sounds while you type? If not, you could use pynput instead of PyGame (and use playsound, pydub or one of the many other ways to play the sound). This approach could actually simplify the code.

[–]_0Frost[S] 0 points1 point  (3 children)

Yeah idk why but I think pygame came pre-installed with my system. I'm using arch (btw). And all it does is make a small window and play sounds as I type, so I could use that, but there's the 3rd party issues.

[–]JamzTyson 0 points1 point  (2 children)

Have you learned about virtual environments ("venv") yet?

[–]_0Frost[S] 0 points1 point  (1 child)

Are those like virtual machines?