Skip to content

Instantly share code, notes, and snippets.

@dev001hajipro
Created October 9, 2017 02:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dev001hajipro/7aa5d666f6d6f350b869d7ebc0baf220 to your computer and use it in GitHub Desktop.
pyautoguiでマウスを移動してみる
#!/usr/bin/env python
"""
pyautoguiを使う
"""
import pyautogui
class Status:
def __init__(self):
self.x, self.y = pyautogui.position()
# 現在のマウスカーソルを退避
def push(self):
self.x, self.y = pyautogui.position()
# 保持しているマウスカーソルに戻す。
def pop(self):
print("x:%s, y:%s" % (self.x, self.y))
pyautogui.moveTo(self.x, self.y)
def main():
stat = Status()
# pyautoguiの設定
# 処理が1秒ごとになる。
pyautogui.PAUSE = 1
# スクリーンの左上にマウスを移動すると、FailSafeExceptionが発生
pyautogui.FAILSAFE = True
stat.push()
# マウスカーソルの移動
width, height = pyautogui.size()
print("width:%s, height:%s" % (width, height))
for i in range(1):
# moveToは絶対座標で指定する
pyautogui.moveTo(100, 100, duration=0.25)
pyautogui.moveTo(200, 100, duration=0.25)
pyautogui.moveTo(200, 200, duration=0.25)
pyautogui.moveTo(100, 200, duration=0.25)
stat.pop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment