Skip to content

Instantly share code, notes, and snippets.

@arsenlosenko
Created August 13, 2017 11:45
Show Gist options
  • Save arsenlosenko/1a796e0eb29b9980f9c4dcb9401cda39 to your computer and use it in GitHub Desktop.
Save arsenlosenko/1a796e0eb29b9980f9c4dcb9401cda39 to your computer and use it in GitHub Desktop.
Example of PyAutoGUI framework for work automation outside of the browser
#!/usr/bin/env python3
"""
Example of PyAutoGUI framework for work automation outside of the browser
"""
import pyautogui
# get width and height of the display
width, height = pyautogui.size()
print("Width of the screen: {}\n"
"Height of the screen: {}".format(width, height))
def move_mouse_to():
for i in range(5):
print("moving mouse randomly")
pyautogui.moveTo(100, 100, duration=0.25)
pyautogui.moveTo(200, 100, duration=0.25)
pyautogui.moveTo(100, 200, duration=0.25)
pyautogui.moveTo(100, 200, duration=0.25)
def move_mouse_rel():
for i in range(10):
print("moving mouse relatively to it's current position")
pyautogui.moveRel(100, 0, duration=0.25)
pyautogui.moveRel(0, 100, duration=0.25)
pyautogui.moveRel(-100, 0, duration=0.25)
pyautogui.moveRel(0, -100, duration=0.25)
def get_mouse_position():
try:
while True:
x, y = pyautogui.position()
coordinates_string = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(coordinates_string, end="")
print('\b' * len(coordinates_string), end='', flush=True)
except KeyboardInterrupt:
print('\nDone')
if __name__ == '__main__':
# move_mouse_rel()
# move_mouse_to()
get_mouse_position()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment