You cannot access other's drafts.
while 1:
s = ord(msvcrt.getch())
if s in [81, 113]:
break
if a > 0:
.........
if b:
.....
用这个方法它会一直停在 ord 那行等待输入。
怎么能让它不影响下面的 if 运行。又能在按 q 时退出 呢?
谢谢
多线程试了一下,是可以的
import time
import asyncio
import msvcrt
import threading
s = True
def func2():
in1 = input("是否暂停: ")
if in1 == "q":
global s
s = False
def func1():
counter = 0
while True:
if not s:
break
counter += 1
with open("log.txt", "a+") as f:
f.write(f"{counter} \n")
time.sleep(1)
t1 = threading.Thread(target=func2)
t2 = threading.Thread(target=func1)
li = [t2, t1]
for i in li:
i.start()
for i in li:
i.join()