โš ๏ธ 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: Robbi Nespu

Edit

Have some thoughts, discussion or feedback on this post?

๐Ÿ’ฌย Send me an email

What is webmention? How to send interactions!

Below you can find all of webmention with this page. Which means, you also can mentioned this URL on any website that support WebMention. Have you written a response to this post? Let me know the URL:

Do you use a website that don't have WebMention capabilities? You can just use Comment Parade!