Skip to content

Instantly share code, notes, and snippets.

@dev001hajipro
Created October 11, 2017 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev001hajipro/ba748bb5274a9e48e5c19603a65295de to your computer and use it in GitHub Desktop.
Save dev001hajipro/ba748bb5274a9e48e5c19603a65295de to your computer and use it in GitHub Desktop.
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