Create a gist now

Instantly share code, notes, and snippets.

Embed
pyautoguiでイメージ認識、キーボード入力
#!/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