Sign in to follow this  
Followers 0
ilan2212

New to Scritpting.

12 posts in this topic

#1 ·  Posted (edited)

Hey comrades!

I need help creating a script , that will click the lef mouse button continuously with a certain delay between clicks , all while I'm holding a button.

So far , I figured out I need , but I'm having a hard time putting it all together.

Help would be much appreciated.Thanks

Edited by ilan2212

Share this post


Link to post
Share on other sites



Welcome to the forums!

To start somewhere, I'd use the example code from the Hotkeyset in the helpfile. Then add the mouseclick commands to that. After that the Winwaitactive can be dealt with. Throw some of that code together and show us your results, we can help from there.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hey there , let me rephrase my request:

How do I set a conditional - while some key is pressed , do this and that

Edited by ilan2212

Share this post


Link to post
Share on other sites

Pres enter to simulate left mouse click,It currently clicks on current x y location, see help file if u need to click on given coordinates

HotKeySet("{enter}","_function")
;keep program running
while 1
    Sleep(50)
WEnd
;user defined function
Func _function()
    MouseClick("left")
;Add more commands here!!!!
EndFunc

edited

Share this post


Link to post
Share on other sites

Hey comrades!

I need help creating a script , that will click the lef mouse button continuously with a certain delay between clicks , all while I'm holding a button.

So far , I figured out that I need to use the MouseClick/MouseClickDelay , WinWaitActive , Send/HotKeySet and some other loop and conditional commands ,

but I'm having a hard time putting it all together.

Help would be much appreciated.Thanks

Welcome to the AutoIt forums ilan2212 :)

As the others have said, the help is the place to start, but I also think they have been a little harsh considering you have obviously looked and said you are lost, and I'm just a sucker sometimes I guess.

I think the logic needs to be something like

wait till the special key is pressed (as you say Hotkeyset can be used)

have a function which presses the mouse button every so many mS untill the key is released.

So you need some way of knowing when the key is still pressed even when your hotkey function responds. Also, there is the problem that if the key is held down, auto repeat will mean that the hotkey function will keep getting called so you have to avoid that.

_IsPressed is the funtion you don't know about to tell if a key is pressed.

You don't need to set the mouseClickdelay to set the time between clicks because you can just use a sleep.

So you could have something like this which is just something to play with

#include <misc.au3>;need this to use the _IsPressed function

HotKeySet("{F9}", "ClickFn")
HotKeySet("{ESC}", "MyExit")

While 1
    Sleep(90);just wait untill something happens
WEnd

Func ClickFn()
    ConsoleWrite("started in ClickFn" & @CRLF)
    HotKeySet("{F9}");turn off the hotkey
    While _IsPressed("78");code for F9
        MouseClick("left")
        Sleep(1200)
    WEnd
   ;if the script gets here then the key is released so we can set the hotkey back
    HotKeySet("{F9}", "ClickFn")
    ConsoleWrite("finished in ClickFn" & @CRLF)
EndFunc  ;==>ClickFn

Func MyExit()
    Exit
EndFunc  ;==>MyExit

You need to study the help for anything that you don't understand in that, and play around with changes to see the effects.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Here is what I did:

WinWaitActive("App")
HotKeySet("v", "LeftClick")
While 1=1
    sleep ( 100 )
    Func LeftClick ()
        MouseClick("left")
    EndFunc
WEnd

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Here is what I did:

WinWaitActive("App")
 HotKeySet("v", "LeftClick")
 While 1=1
     sleep ( 100 )
     Func LeftClick ()
         MouseClick("left")
     EndFunc
 WEnd
It's better practise to set the hotkey first, it doesn't matter which way it goes really.

Functions are created outside of the While loop:

WinWaitActive("App")
 HotKeySet("v", "LeftClick")
 While 1
     sleep ( 100 )
 WEnd
Func LeftClick ()
      MouseClick("left")
  EndFunc

Edit: Also, While 1=1 can just be While 1. 1 is true so While True could work too.

Edited by JamesBrooks

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

you cant run a function in a while like that. Try this i added a activate

HotKeySet("v", "LeftClick");Sets hotkey

WinActivate("App");activates a window already started.
WinWaitActive("App");waits till window is active


While 1
    Sleep(100)
    LeftClick () ; runs your func
WEnd
 
Func LeftClick ()
         MouseClick("left")
EndFunc

EDIT: Didnt see James

Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Wow , thank you all for the quick replies and tips!

It seems that the HotKeySet way isn't right for me , because its toggle , and that's what I need. Again , maybe I'm wrong.

I want the same key , while pressed , to perform the action , and when released , to cease. Is that possible?

EDIT: woops , didn't see you there martin , It works! thanks alot!

Now just understanding it... hehe =]

Edited by ilan2212

Share this post


Link to post
Share on other sites

Maybe _IsPressed is more what you need. Create a loop around it then do some action based on it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0