我编写了一个Python脚本来检测Print Screen按键,并启动代码片段工具。该脚本使用subprocess.call来处理应用程序的启动。
我面临的问题是,当我完成截取工具并关闭应用程序时,我得到一个“额外的”应用程序正在启动。例如,如果我截取了一个PowerPoint演示文稿,那么当我关闭截取工具时,我会得到一个自动启动的新的/空白的Power Point实例。我不希望这种情况发生,只希望截取工具关闭,没有任何额外的行动。
有人能帮我解释一下我的代码中遗漏了什么吗?
# https://stackoverflow.com/questions/24072790/detect-key-press-in-python
# https://pypi.org/project/keyboard/
# https://github.com/boppreh/keyboard#api
import keyboard #pip install keyboard
import time
import subprocess
while True:
if keyboard.is_pressed('print screen'):
subprocess.call(r'SnippingTool.exe') # blocking; waits until open
keyboard.press_and_release('ctrl+N')
#elif keyboard.is_pressed('ctrl+print screen'): # not recognizing "print screen" here
elif keyboard.is_pressed('ctrl+esc'):
print 'killing it now'
break
else:
time.sleep(0.1)发布于 2018-12-20 02:27:33
我猜(我不是在Windows上),但我认为subprocess.call会等到你使用完截取工具,所以keyboard.press_and_release('ctrl+N')会转到PowerPoint。
https://stackoverflow.com/questions/53854317
复制相似问题