โ ๏ธ Warning: This post is over a year old, the information may be out of date.
๐ Python ๐ - active screen cursor movement
๐ | โฐ 1 minutes
Sometimes, I need to let the computer running so I can monitor logs
or make some application not goes to sleep.
So I use this python script to make random mouse movement and pressing some keyboard stroke on some interval of time.
import time as t
import random as rand
from pynput.mouse import Controller as mouseController
from pynput.keyboard import Key, Controller, Listener
import keyboard as keyb
# This function will move the cursor and
# press 'space' every couple of seconds
def active_cursor_mover():
start = t.time()
mouse = mouseController()
keyboard = Controller()
while True:
# Random movements
movedirX = rand.randint(-100, 100)
movedirY = rand.randint(-100, 100)
mouse.move(movedirX, movedirY)
keyboard.press(Key.space)
# Every _ seconds
t.sleep(2.0 - ((t.time() - start) % 2))
if __name__ == '__main__':
active_cursor_mover()
You need 2 python package to make it run
pip install pynput keyboard
so use ‘venv’ or any python virtual enviroment and run the script. She will do the job…
Posted by: Hugo