4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

3分ごとにマウスを動かす

Last updated at Posted at 2018-04-02

##python3で3分毎にマウスを動かす
会社支給のスクリーンセーバーがうざいのをマイコンで対処したという旨のツイートを見かけたので、これはスクリプトでもできるのではという思いから書いてみました。
pyautoguiが入っていない場合pipで入れます。これはGUI環境で行ってください。
SSH等リモート接続の場合KeyErrorが発生するようです。

pip install pyautogui
mouse.py
# -*- coding: utf-8 -*-
 
import pyautogui
import time
 
#click()でエラーが出るときはこっちを使う
def click1():
    try:
        pyautogui.click()
    except PermissionError:
        pass
 
if __name__ == "__main__":
    while True:

        #待つ(秒)
        time.sleep(180)
 
        #マウス現在地取得
        #pos = pyautogui.position()
        #print(pos)
 
        #マウス移動
        pyautogui.moveRel(-50, 0) #相対座標
        pyautogui.moveRel(50, 0)
        #マウス現在地取得
        #pos2 = pyautogui.position()
        #print(pos2)

4
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?