moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

sound not playing on keypress #403

Closed nickplj12 closed 3 years ago

nickplj12 commented 3 years ago

Description A clear and concise description of what the bug is. the sound is not playing on keypress with playsound, but it works fine on other keys

Platform and pynput version Your operating system and version, and the version of pynput. Windows 10 Home 21H1 Pynput 1.7.3

To Reproduce If possible, please include a short standalone code sample that reproduces the bug. Remember to surround it with code block markers to maintain indentation!

from pynput.keyboard import Key, Listener
from playsound import playsound

def on_press(key):
    print('{0} pressed'.format(key))
   #playsound("sounds/nk-cream/a.wav", False)
    if key == Key.space:
        playsound("sounds/nk-cream/space.wav")

...

    elif key == 'q':
        playsound("sounds/nk-cream/q.wav")
    elif key == 'w':
        playsound("sounds/nk-cream/w.wav")
    elif key == 'e':
        playsound("sounds/nk-cream/e.wav")
    elif key == 'r':
        playsound("sounds/nk-cream/t.wav")
    elif key == 'y':
        playsound("sounds/nk-cream/y.wav")
    elif key == 'u':
        playsound("sounds/nk-cream/u.wav")
    elif key == 'i':
        playsound("sounds/nk-cream/i.wav")
    elif key == 'o':
        playsound("sounds/nk-cream/o.wav")
    elif key == 'p':
        playsound("sounds/nk-cream/p.wav")
    elif key == 'a':
        playsound("sounds/nk-cream/a.wav")
    elif key == 's':
        playsound("sounds/nk-cream/s.wav")
    elif key == 'd':
        playsound("sounds/nk-cream/d.wav")
    elif key == 'f':
        playsound("sounds/nk-cream/f.wav")
    elif key == 'g':
        playsound("sounds/nk-cream/g.wav")
    elif key == 'h':
        playsound("sounds/nk-cream/h.wav")
    elif key == 'j':
        playsound("sounds/nk-cream/j.wav")
    elif key == 'k':
        playsound("sounds/nk-cream/k.wav")
    elif key == 'l':
        playsound("sounds/nk-cream/l.wav")
    elif key == 'z':
        playsound("sounds/nk-cream/z.wav")
    elif key == 'x':
        playsound("sounds/nk-cream/x.wav")
    elif key == 'c':
        playsound("sounds/nk-cream/c.wav")
    elif key == 'v':
        playsound("sounds/nk-cream/v.wav")
    elif key == 'b':
        playsound("sounds/nk-cream/b.wav")
    elif key == 'n':
        playsound("sounds/nk-cream/n.wav")
    elif key == 'm':
        playsound("sounds/nk-cream/m.wav")

...

Every other key works except the letters a-z.

moses-palmer commented 3 years ago

Thank you for your report.

I do not think this is an issue with pynput. The key events are not comparable with strings; have you tried using key.char instead?

moses-palmer commented 3 years ago

I will close this issue, as the cause for the problem seems rather obvious.