Created
October 11, 2017 03:10
-
-
Save dev001hajipro/ba748bb5274a9e48e5c19603a65295de to your computer and use it in GitHub Desktop.
pyautoguiでイメージ認識、キーボード入力
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
pyautoguiでイメージ認識、キーボード入力 | |
メモ帳を画面キャプチャしてmemo.pngとして保存する必要あり。 | |
""" | |
import pyautogui | |
def recognize_image(src): | |
coords = pyautogui.locateOnScreen(src) | |
if coords is None: | |
print('not found image.') | |
else: | |
print(coords) | |
print(pyautogui.center(coords)) | |
center_pos = pyautogui.center(coords) | |
# 移動 | |
pyautogui.moveTo(center_pos[0], center_pos[1]) | |
pyautogui.click(center_pos[0], center_pos[1]) | |
pyautogui.typewrite('hello world!', 1.0) | |
def main(): | |
recognize_image('memo.png') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment