keysound
- 1 Devlogs
- 1 Total hours
a python script that adds custom sounds to your keyboard
a python script that adds custom sounds to your keyboard
After making the Lenny Face-er (a stupid program that allows you to open up a menu at any time to copy and paste lenny faces), I got kind of excited at using the pynput library in python. It allows you to detect universal key presses.
So once again, I want to make something lightweight, so I’m using tkinter for the GUI. Right now, I have the basic function of it worked out. You press a key and a sound comes out.
Pynput still detects a key is pressed even when it’s being held down. I don’t want a sound to be played over and over just because a key is held down. To solve this, I added a list named keys_pressed. Basically, how this works is that whenever a key is pressed, that key is added to the list through keys_pressed.append(key) and once the key is detected to be released, we remove that key by running keys_pressed.remove(key). However, special function keys, like CTRL and ALT need to be converted to match the alphanumeric keys.
At first, I tested using the playsound3 library. However, it made the sounds EXTREMELY delayed. That’s because the playsound library stops everything else in your script to play the sound. That’s not what I wanted, so I used the pygame library. For some reason, mixer wasn’t working so I resorted to using the pygame-ce version (I’m too lazy to find the real issue). Anyway, it was much faster, and I also converted to using .wav files. However, when typing fast, some sounds were still not playing. I fixed this by making each sound play in a different channel, so the sounds wouldn’t cover each other up.
What I want to work on next is the GUI. I want to add a feature where users can easily switch between sounds. Right now, I have 4 different keyboard sounds, but to switch between them, you have to go into the code and find the variable called key_sound (ayo the name of the project!!) and set it to the file path. I’m gonna add buttons so it becomes an easy user experience.