Created
July 29, 2021 03:58
-
-
Save sbolel/7d33c8fc8d6062ddb2868270e7e5aa27 to your computer and use it in GitHub Desktop.
MacOS Mouse Mover (Python) - prevent sleep while idle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import sched | |
import time | |
from Quartz.CoreGraphics import CGEventCreateMouseEvent, kCGMouseButtonLeft, CGEventPost, kCGHIDEventTap, kCGEventMouseMoved, kCGEventLeftMouseDown, kCGEventLeftMouseUp, CGEventCreate, CGEventGetLocation | |
def mouseevent(type, posx, posy): | |
event = CGEventCreateMouseEvent(None, type, (posx, posy), kCGMouseButtonLeft) | |
CGEventPost(kCGHIDEventTap, event) | |
def mousemove(posx, posy): | |
mouseevent(kCGEventMouseMoved, posx, posy) | |
def mouseclick(posx, posy): | |
mouseevent(kCGEventLeftMouseDown, posx, posy) | |
mouseevent(kCGEventLeftMouseUp, posx, posy) | |
def main(): | |
mousemove(25, 5) | |
mouseclick(25, 5) | |
time.sleep(5) | |
mousemove(700, 5) | |
mouseclick(700, 5) | |
time.sleep(5) | |
s = sched.scheduler(time.time, time.sleep) | |
def do_something(sc): | |
main() | |
s.enter(0, 1, do_something, (sc,)) | |
print("Starting idler...") | |
s.enter(0, 1, do_something, (s,)) | |
s.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment