0

I'm trying to make a script using the winsound, keyboard, and pyautogui modules. I want it to play when a pixel at the dedicated coordinates on screen is white and when the quit key (q) isn't pressed. Here is what I've tried

while keyboard.is_pressed("q") == False:
    if pyautogui.pixel(343, 846) [0] == 255:
            winsound.PlaySound("bt.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
    else:
        winsound.PlaySound(None, winsound.SND_PURGE)

I'm pretty sure this doesn't work because it just keeps looping trying to play the sound so it never actually starts. I probably explained this poorly so lmk if you need me to elaborate.

Mitchell
  • 27
  • 4
  • If you push `q` does this code stopped? I am suspicious some other process is running at the same time with your Python code. – Cloud Cho Jun 20 '20 at 03:31
  • yes it stops the code – Mitchell Jun 20 '20 at 04:36
  • I want to suggest some processing time measurement. It looks like that `PlaySound` function not able to executed on given time in the While loop. One way to check is using key stroke rather than screen pixel value. – Cloud Cho Jun 23 '20 at 17:29

0 Answers0