March 28th, 2005, 04:48 PM
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.
March 28th, 2005, 06:59 PM
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
March 28th, 2005, 07:19 PM
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.
March 28th, 2005, 10:00 PM
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
March 29th, 2005, 02:44 AM
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 02:48 AM.
March 29th, 2005, 07:29 AM
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