Jump to content

New to Scritpting.


Recommended Posts

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
Link to comment
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.

Link to comment
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

Link to comment
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.
Link to comment
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
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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...