Skip to content

Instantly share code, notes, and snippets.

@saidsef
Last active January 15, 2018 03:43
Show Gist options
  • Save saidsef/a6fd5cab2e12a77ff4834feace7bc6a9 to your computer and use it in GitHub Desktop.
Save saidsef/a6fd5cab2e12a77ff4834feace7bc6a9 to your computer and use it in GitHub Desktop.
Magic Mouse - Keep awake
#!/usr/bin/env python
# Copyright (c) 2018, Said Sef. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
##
# You'll need to install pynput
# pip install pynput
##
from pynput.mouse import Button, Controller, Listener
from threading import Thread
from random import randint, randrange
from time import sleep
import logging
class Mouse(Thread):
logging.getLogger()
logging.basicConfig(level=logging.DEBUG)
def __init__(self):
self.mouse = Controller()
def move(self):
self.mouse.move(randint(5,50), randint(-10,20))
self.mouse.scroll(randint(0,2), randint(-5,5))
#self.mouse.click(Button.left, randint(0,2)) # only to drive someone insane
logging.debug("current mouse position {}".format(self.mouse.position))
sleep(randint(0,5))
if __name__ == '__main__':
mouse = Mouse()
try:
while True:
mouse.move()
except KeyboardInterrupt as e:
pass
finally:
del mouse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment