Created
October 9, 2017 02:16
Star
You must be signed in to star a gist
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 | |
""" | |
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