简体   繁体   English

检测到Python键,但未运行其他代码

[英]Python-Key press detected , but not running other codes

I want to make a program that when I press Q, It takes a screenshot and save it. 我想制作一个程序,当我按Q时,它将截屏并保存。 It can detect the keypress but doesn't run the other codes. 它可以检测到按键,但不运行其他代码。

a = input()
b = ''
import time
import pyautogui
import PIL
import keyboard # Using module keyboard
while True: # making a loop
    try: 
        if keyboard.is_pressed('q'): # if key 'q' is pressed
            print('Detected')
            a+=1
            im = pyautogui.screenshot()
            b = ''
            b = str(a)
            b+=".jpg"
            im.save(b)
            print('Success')
            time.sleep(1)
        else:
            pass
    except:
        b = ''

But the results just come like this: 但是结果只是这样:

Detected
Detected
Detected
Detected
Detected
Detected
Detected
Detected
Detected
Detected
Detected

It just prints a lot of 'Detected' and doesn't run anymore. 它只会打印很多“检测到”并且不再运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM