Introduction
In today’s fast-paced world, automation has become an essential aspect of improving efficiency and productivity. In this article, we’ll explore how to automate mouse movements on a server using Python. This can be particularly useful for keeping applications active, such as Microsoft Teams, during specific times each day.
Prerequisites
Before diving into the steps, ensure that you have the following:
- A server with the necessary permissions.
- Python installed on your server.
- The
pyautogui
library installed (pip install pyautogui
).
Writing the Python Script
Let’s create a Python script that moves the mouse in circles. This script will be scheduled to run automatically at a specific time each day.
# Python script for automating mouse movements
import pyautogui
import time
import math
def move_mouse_in_circles(duration, radius=100, speed=30):
start_time = time.time()
while time.time() - start_time < duration:
angle = (time.time() - start_time) * speed
x = int(radius * math.cos(angle)) + pyautogui.size()[0] // 2
y = int(radius * math.sin(angle)) + pyautogui.size()[1] // 2
pyautogui.moveTo(x, y)
time.sleep(0.01)
# Set the total duration to move the mouse in circles (in seconds)
total_duration = 60 # 1 minute
# Call the function to move the mouse in circles
move_mouse_in_circles(total_duration)
Scheduling the Script
For Windows
- Open Task Scheduler (
taskschd.msc
). - Click on “Create Basic Task” and follow the wizard to set up a new task.
- Set the trigger to “Daily” and specify the time.
- In the “Action” section, select “Start a Program” and provide the paths to Python and your script.
- Complete the wizard and save the task.
For Linux
- Open the crontab file for editing (
crontab -e
). - Add a line to schedule your task at a specific time each day, specifying the Python and script paths.
- Save the file.
Conclusion
Automating mouse movements on a server can be a powerful tool for maintaining the activity of applications. By following this step-by-step guide, you can set up a Python script to move the mouse at a scheduled time each day, ensuring that your applications stay active when needed.
Remember to adjust the script parameters, such as the circle radius and speed, to fit your specific requirements. Happy automating!