You are browsing as a guest. Sign up (or log in) to start making projects!

keysound

  • 1 Devlogs
  • 1 Total hours

a python script that adds custom sounds to your keyboard

Open comments for this post

44m 35s logged

keysound Devlog 1

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.

What better way to play with it than make it play clicking sounds!

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.

Things I’m a little proud of

Detecting when a key has already been pressed

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.

Playing the sounds

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’s next?

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.

0
0
2

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…