Skip to content

Instantly share code, notes, and snippets.

@prehistoricpenguin
Last active August 29, 2015 14:03
Show Gist options
  • Save prehistoricpenguin/a0072676a933809d8ee8 to your computer and use it in GitHub Desktop.
Save prehistoricpenguin/a0072676a933809d8ee8 to your computer and use it in GitHub Desktop.
# A script used to move mouse cursor slightly
# every 5 minites when there'is no mouse movement
# to run in background under win32:
# pythonw.exe movecursor.py
import time
import win32gui
import win32api
def movecursor():
lasttime = time.time()
lastpos = win32api.GetCursorPos()
diffinsecs = 5 * 60
movedir = 1
while True:
curtime = time.time()
timediff = curtime - lasttime
curpos = win32api.GetCursorPos()
if timediff >= diffinsecs:
if curpos == lastpos:
lasttime = curtime
curpos = (curpos[0] + movedir, curpos[1] + movedir)
movedir = movedir * -1
win32api.SetCursorPos(curpos)
# print lastpos, " -> ", curpos
# print "movdir :", movedir
# print "moved, now time\t", curtime
lastpos = curpos
else:
#print "will sleep ", diffinsecs - timediff, " sec"
time.sleep(diffinsecs - timediff)
if __name__ == "__main__":
movecursor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment