Quick: neat python library PyAutoGui

1 A very useful python library

Yesterday a bit after I would usually have gone to bed, I was somehow still hanging around my computer, looking around on the web, for no good reason. Then I decided probably against better judgement to look at playing a clicker game, it just so happened to be cookie clicker, which is not really important for this post. But just clicking on the mouse is a really bad idea, with repetitive stress injury and such, so I decided it would make more sense to write some code to click the mouse on the specific part of the screen. Windows users can do this by just using AutoHotKey, and in fact me as a linux user is somehow missing this fantastic tool for productivity gains, however I did find something that does something similar a python library that is cross platform, and allows you to do a lot of similar things.

```pyautogui```

This is actually an awesome library, I only really tested a small part of the functionality, but I think it could be a very useful thing, and being an linux you can easily make keyboard strokes launch a python script that does something specific.

import pyautogui as pag
import time # just to have the ability to sleep.

This was all the things I needed, now you can move the mouse around on the screen, by giving it coordinates 0,0 is the upper left corner. The arguments are down

import pyautogui as pag
import time # just to have the ability to sleep.
pag.moveTo(200,1000)

This code will warp your cursor to the selected location, 200 hundred move x position to 200 and 1000 moves the y position aka down. You can specify either a click on coordinates, or you can move to a coordinate and use click without the coordinates.

pag.click()

This will click the mouse where it is currently, whereas

pag.click(200,400)

will move the mouse to these coordinates to click.

More information

Check out the documentation^^

1 Comment