【发布时间】:2018-12-10 22:02:47
【问题描述】:
import pyautogui, time, threading, keyboard, msvcrt
global active, exitp
active = False
exitp = False
Names = []
def mainLoop():
global active, exitp
pressedkey = msvcrt.getch()
while True:
if pressedkey == 'z':
active = not active
elif pressedkey == 'x':
exitp = False
break
def running():
global exitp
while not exitp:
print("Running")
time.sleep(3)
start = time.time()
print("Your screen size is: " + str(pyautogui.size()))
width, height = pyautogui.size()
t1 = threading.Thread(target=mainLoop, args=())
t2 = threading.Thread(target=running, args=())
t1.start()
t2.start()
while not exitp:
if active:
pyautogui.click(90, height - 110)
for i in range(len(Names)):
if active:
pyautogui.typewrite(Names)
pyautogui.press("enter")
else:
break
active = False
end = time.time()
print("Execution time: " + str(end-start) + " seconds")
尝试创建一个循环,当我按下“x”时退出,并在按下“z”时从名为“Names”的数组中键入/停止键入名称,但是,我同时按下“x”和“z”但他们什么也没做,帮忙?
【问题讨论】:
标签: python keyboard key python-multithreading msvcrt