pagテスト

投稿者: | 2022-04-18
  • まだ作成中
import pyautogui as pag
import pathlib
import sys
import time

pag.PAUSE = 1
pag.FAILSAFE = True

def action():
  time.sleep(1)
  pag.hotkey('command', 'tab')
  time.sleep(2)

# 精度を上げるなら
# target_range = (1576, 126, 328, 79) 
# p = pag.locateOnScreen("test.png", region=target_range)


  img_file = '/Users/mbp441/Desktop/test/file.png'
  icon_center = pag.locateCenterOnScreen(img_file)
  if icon_center:
    print(f'発見: {img_file}')
    x, y = icon_center
    pag.click(x/2,y/2)
    time.sleep(1)
  else:
    print('見つからず')

  pag.hotkey('command', 'tab')  
  

while True:
    
  try:
        
    select_no = input('\n<処理を選んでください>\n\n[1]:東北のアンペア違い\n[2]:\n[3]:終了\n\n:') 

    if select_no == str(1):
      action()
  
    elif select_no == str(3):
      sys.exit()
    else:
      pass
    
  except pag.FailSafeException as e:
    print('フェールセーフ例外が発生しました。処理を中断します')
    print(e)

カテゴリー: GUI