#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    NY
    Posts
    2
    Rep Power
    0

    Simulating Mouse Clicks in Python


    Anyone know how to simulate a mouse click?...i.e. I give it a position on the screen and say right or left click here.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Depends on what you want to do? If you're thinking of automating a web browser, I have a solution for you.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Scorpions4Ever's IEC (Internet Explorer Controller)would be good for automating a web browser. However, I think he means make the mouse click in specified areas of the screen. There might be a module for that.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    NY
    Posts
    2
    Rep Power
    0
    I would like to automate processes on my computer like adjusting settings inside an application...so basically wanna feed a coordinate and have the mouse click there...but would love to hear the solution for the browser
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    There is no way to do this built into Python, but there are a couple of options. I assume you are using a Windows machine.

    1) Install Autoit, a freeware program that enables you to control programs by simulating mouseclicks and keypresses through its own scripting language. It also has a COM interface that can be called from Python.

    2) Use Watsup, a python library for GUI test automation. This manipulates the GUI controls directly, rather than simulate mouse movements, so is the scripts will be more robust. It uses Simon Brunning's winGuiAuto code for the low-level stuff. Simon's articles give a good introduction to controlling windows GUIs through Python.

    Simulating mouse movements is a very fragile way of controlling anything, since if a window opens in a different place when you replay the script then you are screwed. I would go with Watsup if possible, and only use the other option where absolutely necessary.


    Dave - The Developers' Coach
    Last edited by DevCoach; March 29th, 2005 at 01:48 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    Simulating mouse movements is a very fragile way of controlling anything, since if a window opens in a different place when you replay the script then you are screwed.
    Or if the window changes shape/size, or if another window opens in front, or if the program unexpectedly pops up a "would you like to check for updates?" kind of message, or if you change screen resolutions, or if the program takes a moment to process something and ignores the next mouse click...

    Comments on this post

    • jacktasia agrees

IMN logo majestic logo threadwatch logo seochat tools logo