Not understanding

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Not understanding

23 Sep 2021, 22:59

So here is my code. I think it is pretty clear what I am attempting to do, but for some reason, the first works fine, but the second sends the first as well I think, or is just running too fast with no sleep. I know I am not understanding the fundamentals of this language. Sorry.

Code: Select all

#MaxThreadsPerHotkey, 2
SetDefaultMouseSpeed, 0
SetBatchLines, -1
ListLines, Off

Numpad9::
    bFlag := !bFlag
    While bFlag
        Click
Return

Numpad6::
    cFlag := !cFlag
    While cFlag
        Click
	sleep, 3000
Return
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Not understanding

23 Sep 2021, 23:06

While accepts a block in braces. With no such block, the command applies only to the individual statement that follows it. Example

Explained: Blocks
Last edited by mikeyww on 23 Sep 2021, 23:07, edited 1 time in total.
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Not understanding

23 Sep 2021, 23:07

Thank you. Brackets... I knew it was probably something so simple.
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Not understanding

23 Sep 2021, 23:17

Idk how but it seemed to bug out and now it just doesn't want to stop. Only the Numpad6 though.
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Not understanding

23 Sep 2021, 23:19

Test in Notepad.

Code: Select all

#MaxThreadsPerHotkey 2
Numpad6::
cFlag := !cFlag
While cFlag {
 Click
 Sleep, 1000
}
Return
Or:

Code: Select all

Numpad6::SetTimer, Numpad6 Up, % (on := !on) ? 1000 : "Off"
Numpad6 Up::Send % on ? "{LButton}" : ""
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Not understanding

24 Sep 2021, 12:49

I used the code perfectly fine for MANY hours turning it on and off, and randomly it bugged out again.
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Not understanding

24 Sep 2021, 13:57

Post your revised script, describe exactly what happened when you ran it, and whether there is any additional code in the script or other scripts running.
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Not understanding

24 Sep 2021, 14:03

Code: Select all

#MaxThreadsPerHotkey 10
ListLines, Off

Numpad9::
  bFlag := !bFlag
  While bFlag
    Click
Return

Numpad6::
cFlag := !cFlag
While cFlag {
  Click
  Sleep, 3000
}
Return
Was using it normally. I kinda just want to chalk it up to a computer glitch.
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Not understanding

24 Sep 2021, 14:43

I see no problems with the script itself. If you are sending clicks rapidly without any sleep (first subroutine), I'd say that unintended effects are somewhat likely to occur, simply due to the speed of clicks. As you move the mouse to various points on the screen, it may lead to unexpected effects, because the click will always occur at the mouse's current location (as no coordinates are specified in the script).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 173 guests