Untitled
from pynput import keyboard import ctypes # Function to mute the computer def mute(): # Constants WM_APPCOMMAND = 0x319 APPCOMMAND_VOLUME_MUTE = 0x80000 # Get the handle for the foreground window hwnd = ctypes.windll.user32.GetForegroundWindow() # Send the mute command ctypes.windll.user32.SendMessageW(hwnd, WM_APPCOMMAND, 0, APPCOMMAND_VOLUME_MUTE) # Function to be called when a key is pressed def on_press(key): try: if key == keyboard.Key.down: mute() except AttributeError: pass # Start listening to the keyboard with keyboard.Listener(on_press=on_press) as listener: listener.join()
Leave a Comment