《Python编程快速上手—让繁琐工作自动化》第18章

18.14.1 看起来很忙

import pyautogui,time

pyautogui.FAILFAFE = True

try:
    while True:
        time.sleep(5)
        pyautogui.moveRel(10, 10, duration=0.25)
        pyautogui.moveRel(-10, -10, duration=0.25)
except KeyboardInterrupt:
    print('Done')

即时通信机器人

import pyautogui as gui
import time, sys

gui.PAUSE = 0.2
picture = 'reciever.PNG'
text = 'Hello World!'

try:
    print('Locating the position...')
    gui.click(gui.locateCenterOnScreen(picture))
except TypeError:
    print('Fail to finding the position')
    sys.exit()
    
print('Ready for sending...')
gui.typewrite(text)

print('You have 5 seconds to check it before sending the message.\
Press CTRL-C to stop.')
try:
    time.sleep(5)
    gui.press('enter')
except KeyboardInterrupt:
    print('You have stop sending the message.')

print('Done')

你可能感兴趣的:(《Python编程快速上手—让繁琐工作自动化》第18章)