Useless Hack a Week.

Magma Keys, make each key press a little more exciting

Cover Image for Magma Keys, make each key press a little more exciting
Nick
Nick

Sin City wasn't made for you.... But Magma Keys was!

This weeks hack is a hack that allows you to tie any audio file you want to your keyboard! Whether you set it up to make your keyboard a super annoying internal soundboard, or make each key press sound like a mechanical keyboard, its all up to you.

Why?

I was working on some projects with my co-founder, and per usual, a hour or two into my work, my dogs went nuts at the sound of a leaf landing on my driveway.

SHUT THE FUCK UP!!!

This incident also inspired our other product called Animal Fights

I leave my room to calm them down (put them down) and return to continue working.

My co-founder says:

"You have a lot of noisy distractions, I bet it actually has a big impact on your productivity"

He is probably right

It made me realize, peace and quiet is a very important part of productive work, especially as a programmer!

So naturally, as a founder of Useless Hacks, I came up with a genius idea:

What if we made using your computer as distracting and annoying as possible?

Yes, its a soundboard which only you can hear, and its on every key press...

The Hack

We have 2 versions of this hack:

  • single-sound: Every key press triggers the same audio file
  • multi-sound: Every key press triggers a different audio file

Both versions come with 24 premade audio files which you store in the sounds folder of the project, where you can also upload your own keyboard sound effects!

Let's go over how you can customize this program for your own needs!

Implementation

Single Sound

The code configuration for single sound is very straight forward:

import keyboard
import pygame

# Initialize pygame mixer
pygame.mixer.init()

# Load the sound file
SOUND_FOLDER = 'sounds'
SOUND_FILE = 'munch.mp3'  # <---- Specify sound file here 
sound_effect = pygame.mixer.Sound(f"{SOUND_FOLDER}/{SOUND_FILE}")

def play_sound(e):
    if e.event_type == keyboard.KEY_DOWN:  # Ensure the event is a key press
        sound_effect.play()

# Hook every key
keyboard.hook(play_sound)

# Keep the program running
keyboard.wait('esc')

We import the keyboard and pygame library to hook up sound effects to key presses, and we specify which file in our sounds folder should be triggered on any key press Here, we have set the minecraft munch sound effect.

munch

I like this version of this weeks hack a lot, because with the right sound effect, I don't think it is necessarily distracting, and rather just a cool quirky program you can run while you use your computer!

Some cool ideas

  • Mechanical Keyboard/Typewritter
  • Bubble Pops
  • Ambient Sounds

Multi Sound

The code configuration for different sounds for different keys is also straight forward:

import keyboard
import pygame

# Initialize pygame mixer
pygame.mixer.init()

# Load sound files
SOUND_FOLDER = 'sounds'
SOUNDS = {}

# A basic set of keys to track. Adjust this list based on your needs
keys_to_track = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
    # ... add any other keys you have sound effects for
]

for key in keys_to_track:
    try:
        sound_path = f"{SOUND_FOLDER}/{key}.mp3"
        SOUNDS[key] = pygame.mixer.Sound(sound_path)
    except:
        print(f"Couldn't load sound for {key}")

def play_sound(e):
    if e.event_type == keyboard.KEY_DOWN:  # Ensure the event is a key press
        key = e.name
        if key in SOUNDS:
            SOUNDS[key].play()

# Hook every key
keyboard.hook(play_sound)

# Keep the program running
keyboard.wait('esc')

We import the keyboard and pygame library to hook up sound effects to key presses, and we specify which key presses to track and make a sound on when pressed. If we want to assign a specific audio file to a specific key, all we have to do is name the MP4 file after the key:

Key Names

With this version of the hack, we have some cool things we can implement. Since each key is associated with a different sound, we can do a few different things compared to the single sound version.

Some cool ideas

  • Music notes
  • Comic Sound Effects
  • Nature & Animal Sounds
  • Sci-Fi Sound Effects

Conclusion

Keyboard sound effects is a great way to reduce your productivity and distract yourself. But let's be honest, you do that with TikTok already. So download Magma Keys, take on this healthy replacement.

 

Code for this project can be found here!

Do you like unhinged content? Follow me on X! Or Buy me a coffee!