Python Automated Click Script

11,832

Well, I don't have any experience with the Win32 API, however, it should work along those lines:

  1. The Module you are using needs to let you define a callback method for when a click happens

  2. You somewhere set a boolean that tells you that you are currently recorded.

  3. Your callback method stores tuples in a list:
    • The tuples store the timestamp (time.time) and the coordinates.
    • You can even store more information, like right-click or whatever.
  4. When you are done recording you should have every informationen necessary to start replaying :)

(You may also consider this post) Hope it helps!

Share:
11,832
CodeMonkeyAlx
Author by

CodeMonkeyAlx

I'm just a noob looking to learn... Unlike most newbs I run on an honor system. Yes I might grub for answers but I am also not just going to slap those answers into my code. I will look at them and I will see what they do. Right now my coding level as I like to call it is about 3 on a scale of 10. I know basics if you give me code I can understand what it does, I just cant code it myself just yet. Thats is all and may we all enjoy ourselves here.

Updated on June 04, 2022

Comments

  • CodeMonkeyAlx
    CodeMonkeyAlx almost 2 years

    I am working on a program to make python auto click and type something in. I know this has been done before and asked before but no one has asked about recording mouse clicks to be "Played back" later on. I have the basic code set up from tutorials all over the place. I am wondering if I can get a hand with this. Here is what I have to this point:

    import win32api, win32con
    import time
    def click(x,y):
    
        win32api.SetCursorPos((x,y))
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
    
    print "Clicking 300, 300"
    click(300,300)
    
    time.sleep(3)
    
    print "Clicking 800, 800"
    click(800, 800)
    

    How do I make this so the user can input and save a pre-generated script for clicks?