Python Mouse Auto Clicker with PyAutoGui Tutorial 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is up guys in this video we're going to be covering how we can create this auto clicker using pi auto gy and it's going to be using an image recognition sort of service and it's very simple it's going to be very useful in the future when you actually have to identify elements and it's fairly accurate so it's going to help you a lot with creating bots that don't really have api set for them such as my whatsapp bots and we'll just be covering the basic concepts on how this works but as you can see here we have a very good efficiency the only reason our accuracy is low is because i decided to use the double click feature in payout gui otherwise it would be perfect i just find it a lot easier to make sure we click on something when we use the double click but to get started as always you want to open a new project in pycharm and i'm using python 3.8 for this and we want to open the console so the first one we want to install is open cv python and this is just for the image accuracy recognition service then we want to go ahead and pip install pi auto gui perfect and as soon as that is done we can close the terminal and we have to create a new folder and we're going to call this folder images and the next thing we have to do is actually go back to this site because we need to take a screenshot of the circles and the easiest way to do this essentially on macbook or on windows is to just take a screenshot of the whole screen and then go and find that screenshot zoom in and just take another screenshot of that over there so you will end up with a screenshot similar to this one over here it's going to be a very small circle i already have one that's prepared because i mean i put a little bit more effort into making sure that it was centered but once you have your circle screenshot we're just going to copy that and move it into our project and then we're going to click on refractor so inside your project you should have a circle png similar to this one it's also available on my github profile in case you want to get it from there the link is in the description down below so feel more than free to do that but otherwise just copy and paste your circle picture inside the images folder next we want to go ahead and import pi out to gui as pt we're going to create a class to make everything look a bit more clean then we have to create our init block and inside here it's going to take a target underscore png or any image and a speed so we're going to call self dot target underscore png which is going to equal the target png we initialize this class with and the self.speed which is just going to equal the speed we choose later we also want to save our pi outer gui fill safe to true which means at any time if something goes wrong you just have to move your mouse pointer to the top left corner and it will stop the program and this class will only have one function which is nav to image and the first thing we're going to do is insert a try catch block so the try is going to take a position which is going to be pt dot locate on screen and we want to locate the self.target png and give it a confidence level of 0.6 which is 60 next let's go ahead and type in pt move to and we want to get the position at the index of 0 which is going to be the x because this returns an x and a y in the form of a list so at the position of zero we can do plus 15 and it's very important that you edit this based on your screen resolution because it could be plus 10 or it could be plus 20. essentially what that does is let's go back to our circle so when we look for this image our mouse pointer is going to move to the top left corner of this image once it finds it adding plus 15 just make sure that the mouse pointer moves about 15 pixels to the right and we're going to add 15 pixels to the y so that it will also go 15 pixels down and make sure that it clicks on the center so again depending on your screen resolution this might be 20 this might be 5 so make sure you edit that after you test the program but for my computer we can just add plus 15 pixels to both of them so at the index of 1 plus 15 and the duration is going to be the self.speed then every time we find one we are going to call pt double click and you can also put a single click i just found it a lot more reliable when i used the double click now we can go ahead and create an accept block and in case that happens we're going to type in no image found and we're going to go ahead and return zero now let's go ahead and type in main so we can check if name is equal to main and start the program and the first thing we have to do is initialize the clicker and inside here you want to put the target image so we need to provide the path to our circle.png and in case you're wondering how to get this location you can just go ahead and right click on your png it's going to have a section that says copy and you can choose to copy the path the absolute path or path from the content root this is a very easy one to use but in case this one does not work for you just copy the absolute path that one should never fail but we're going to go ahead and copy this one here and again if you just paste that you're going to notice that it's exactly the same as what i just wrote and for the speed we're just going to provide .001 next we're going to create a variable called end and we also need to create an infinite loop which is going to be while true so if the clicker dot nav2 image does not return a 0 it means that we found the image and we can click it otherwise we're going to increment the end plus equal one and this is just going to be used to end the program so if the end is more than 20 attempts then we are just going to break out of this loop which will just finish the program we're also going to go ahead and import sleep from time so from time import sleep and we're going to give this program a two second delay so that we have enough time to switch to the window that has the auto clicker and right before we run the program i want to specify that we should change the confidence level to 80 because i just realized that 60 makes it click on a lot of stuff that's not our circle so make sure this is pretty confident but not 100 now let's go ahead and go to our mouse accuracy.com page we're going to click on this blue circle here we can click on start we start the program here and we move back over here and as you can see maybe we were a bit slow so our mouse pointer didn't really get the chance to click the first ones but otherwise if you find out how to time this correctly it's going to hit all of them and it's quite accurate you can see because of the plus 15 we get the mouse pointer to the center of the circle and that's essentially how the pi outer gui auto clicker works at the end of the screen it's going to say 95 and when it doesn't find any images it's going to exit out of this loop so that we can comfortably continue with the program the concept of this video was essentially that you need to make sure you have a good confidence level and that you have an image to search for and also that you can find out where to click by adjusting the x and the y but with that being said guys i hope you enjoyed this video if you have any questions or comments just leave them in the comment section down below and i'll do my best to answer it otherwise i'll see you guys in the next video
Info
Channel: Indently
Views: 41,109
Rating: undefined out of 5
Keywords: code palace, cde palace, code palce, palace code
Id: heHx628ahE0
Channel Id: undefined
Length: 8min 7sec (487 seconds)
Published: Fri Jun 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.