jacexh / pyautoit

Python binding for AutoItX3.dll
MIT License
269 stars 74 forks source link

How to automate mouse click in (x,y) coordinates using pyautoit? #10

Closed balup34 closed 4 years ago

balup34 commented 8 years ago

Using pyautoit, I am trying to click my mouse LEFT button, 2 times, in the (x=890 and y=574) coordinates.

I have tried the below codes or options:

OPTIONS 1:

autoit.mouse_click(" 'left', 890, 574, 2")
    sleep(2)

OPTIONS 1:

autoit.mouse_click(" left, 890, 574, 2")
    sleep(2)

OPTIONS 1:

autoit.mouse_click(" $MOUSE_CLICK_LEFT, 890, 574, 2")
    sleep(2)

But no success.

How to do this, any idea?

Aareon commented 8 years ago

Is your script only partially working or entirely broken? I notice an issue with your sleep command. Timing is gauged in milliseconds. Also, to use sleep, you must call it from within 'autoit'.

Example: 'autoit.sleep(param)'

Instead of "2", sleep should be "2000". Hope this helps. Keep me posted.

balup34 commented 8 years ago

@Aareon Thanks for your answer.

Now I have tried with below code:

    autoit.mouse_click("$MOUSE_CLICK_LEFT, 890, 574, 2")
    autoit.sleep(2000)

But same issue. I mean its not clicking the LEFT button.

Could you please help me with the format that I am using here. is it correct "autoit.mouse_click("$MOUSE_CLICK_LEFT, 890, 574, 2") ".

Thanks in advance.

balup34 commented 8 years ago

@Aareon . I found the working code.

Its works with :

    autoit.mouse_click("",890, 574, 2)
    sleep(3)

NOTE : If I use autoit.sleep(2000), I am getting following error:

AttributeError: 'module' object has no attribute 'sleep'

balup34 commented 8 years ago

I have referred following link "http://software-test-knowledge.blogspot.in/2014/01/automate-mouse-click-using-autoit.html". By default its choosing left button. That is why my code autoit.mouse_click("",890, 574, 2) is working.

What if somebody want to press RIGHT mouse button here?

Please guide me how to send mouse key info in this code.

Thanks.

balup34 commented 8 years ago

Got the answer for above question too... :)

autoit.mouse_click("left",890, 574, 2)

Aareon commented 8 years ago

Glad you found what you were looking for. Is there an explanation for why 2000ms didn't work, but 2 or 3 does? On Nov 9, 2015 5:53 AM, "balup34" notifications@github.com wrote:

Got the answer for above question too... :)

autoit.mouse_click("left",890, 574, 2)

— Reply to this email directly or view it on GitHub https://github.com/jacexh/pyautoit/issues/10#issuecomment-155044054.

jacexh commented 8 years ago

use time.sleep(2) instead of autoit.sleep() I did not add sleep interface in pyautoit