为什么我在 Python 中使用快捷方式时我的应用程序一直打开?

Why my app keep opening when I use shortcut in Python?

我尝试创建一个程序来使用特定的快捷方式打开应用程序,但是当我按下按键时它一直打开并且直到我停止程序才停止

import keyboard
import time
import subprocess

while True:
    if keyboard.is_pressed('ctrl+space+b'):
        subprocess.Popen([r"C:\Program Files\Everything\Everything.exe"])
        time.sleep(1.5)

试试这个代码怎么样

import keyboard
import subprocess
import threading

def run_my_program():
    subprocess.run([r"C:\Program Files\Everything\Everything.exe"])

while True:
    if keyboard.is_pressed('ctrl+space+b'):
        threading.Thread(target=run_my_program).start()  # launch up the subprocess in parallel so input is not delayed
        while keyboard.is_pressed('ctrl+space+b'):
            pass  # Wait until user lifts his hands off the keyboard