Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# (C) Paul Gupta, 2022
import winsound
from pynput import keyboard
def on_press(key):
if key == keyboard.Key.esc:
exit()
try:
k = key.char
except:
k = key.name
if k in ['a']:
winsound.PlaySound('a.wav', winsound.SND_ASYNC)
if k in ['b']:
winsound.PlaySound('b.wav', winsound.SND_ASYNC)
if k in ['c']:
winsound.PlaySound('c.wav', winsound.SND_ASYNC)
if k in ['d']:
winsound.PlaySound('d.wav', winsound.SND_ASYNC)
if k in ['e']:
winsound.PlaySound('e.wav', winsound.SND_ASYNC)
if k in ['f']:
winsound.PlaySound('f.wav', winsound.SND_ASYNC)
if k in ['g']:
winsound.PlaySound('g.wav', winsound.SND_ASYNC)
if k in ['h']:
winsound.PlaySound('h.wav', winsound.SND_ASYNC)
if k in ['i']:
winsound.PlaySound('i.wav', winsound.SND_ASYNC)
if k in ['j']:
winsound.PlaySound('j.wav', winsound.SND_ASYNC)
if k in ['k']:
winsound.PlaySound('k.wav', winsound.SND_ASYNC)
if k in ['l']:
winsound.PlaySound('l.wav', winsound.SND_ASYNC)
if k in ['m']:
winsound.PlaySound('m.wav', winsound.SND_ASYNC)
if k in ['n']:
winsound.PlaySound('n.wav', winsound.SND_ASYNC)
if k in ['o']:
winsound.PlaySound('o.wav', winsound.SND_ASYNC)
if k in ['p']:
winsound.PlaySound('p.wav', winsound.SND_ASYNC)
if k in ['q']:
winsound.PlaySound('q.wav', winsound.SND_ASYNC)
if k in ['r']:
winsound.PlaySound('r.wav', winsound.SND_ASYNC)
if k in ['s']:
winsound.PlaySound('s.wav', winsound.SND_ASYNC)
if k in ['t']:
winsound.PlaySound('t.wav', winsound.SND_ASYNC)
if k in ['u']:
winsound.PlaySound('u.wav', winsound.SND_ASYNC)
if k in ['v']:
winsound.PlaySound('v.wav', winsound.SND_ASYNC)
if k in ['w']:
winsound.PlaySound('w.wav', winsound.SND_ASYNC)
if k in ['x']:
winsound.PlaySound('x.wav', winsound.SND_ASYNC)
if k in ['y']:
winsound.PlaySound('y.wav', winsound.SND_ASYNC)
if k in ['z']:
winsound.PlaySound('z.wav', winsound.SND_ASYNC)
listener = keyboard.Listener(on_press=on_press)
listener.start()
listener.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment