Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Created October 14, 2016 16:40
Show Gist options
  • Save tbnorth/492e31ef24cc3c367ac141b4faa2a8cd to your computer and use it in GitHub Desktop.
Save tbnorth/492e31ef24cc3c367ac141b4faa2a8cd to your computer and use it in GitHub Desktop.
Python mouse mover for screen saver suppression
"""
Using mouse events rather than just moving the cursor is important
"""
import sys
import time
import win32api
import win32con
last = -1
while True:
for i in range(4):
last *= -1
x, y = win32api.GetCursorPos()
x += 5*last
y += 5*last
nx = x*65535/win32api.GetSystemMetrics(0)
ny = y*65535/win32api.GetSystemMetrics(1)
win32api.mouse_event(
win32con.MOUSEEVENTF_ABSOLUTE |
win32con.MOUSEEVENTF_MOVE,
nx, ny
)
time.sleep(0.1)
print time.asctime(), x, y
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment