-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKey-Sounds.py
43 lines (26 loc) · 848 Bytes
/
Key-Sounds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from pynput import mouse
import pygame
import os
import keyboard
import threading
pygame.mixer.init()
script_dir = os.path.dirname(os.path.abspath(__file__))
sound_file_path = os.path.join(script_dir, 'keysounds.mp3') # Replace 'soundfile.mp3' with your actual sound file name
sound = pygame.mixer.Sound(sound_file_path)
def play_sound():
sound.play()
def on_click(x, y, button, pressed):
if pressed:
print(f"Mouse clicked at ({x}, {y})")
threading.Thread(target=play_sound).start()
def on_key(event):
if event.event_type == keyboard.KEY_DOWN:
print(f"Key pressed: {event.name}")
threading.Thread(target=play_sound).start()
mouse_listener = mouse.Listener(on_click=on_click)
keyboard.hook(on_key)
mouse_listener.start()
try:
mouse_listener.join()
except KeyboardInterrupt:
pass