Need help with hotkey script Topic is solved

Ask gaming related questions (AHK v1.1 and older)
darksham
Posts: 2
Joined: 21 Jan 2023, 16:42

Need help with hotkey script

Post by darksham » 21 Jan 2023, 16:48

Hello,

I'm really new to autohotkey but I would like some help with a script. I need it for a steam mmo so I dont have to click my mouse right key endlessly to attack enemies in game. What I wanted to do was to be able to have a key, for example Num0 key as the activation key to toggle my right mouse button to continuously click until that same Num0 key is pressed again to stop it.

So when I press num0 my right mouse clicks 3-5 times per second. The cps isnt important in the game as it will only click as fast as your attack speed level is raised to but this script would be great if anyone can educate me please?!

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Need help with hotkey script  Topic is solved

Post by mikeyww » 21 Jan 2023, 17:43

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
Numpad0:: {
 Static on := False
 SetTimer () => Click('R'), 80 * on := !on
}

darksham
Posts: 2
Joined: 21 Jan 2023, 16:42

Re: Need help with hotkey script

Post by darksham » 22 Jan 2023, 02:05

mikeyww wrote:
21 Jan 2023, 17:43
Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
Numpad0:: {
 Static on := False
 SetTimer () => Click('R'), 80 * on := !on
}
Thanks very much this script works. But for some strange reason it will only work on any other window except the game window. Would I have to enter the game window program at the top of the script for example:

Also would it be possible to lower the click count. I tried setting a timer for 5 clicks per second as the current one is 1000 cps.

Code: Select all

Redstone.exe
Numpad0:: {
 Static on := False
 SetTimer () => Click('R'), 80 * on := !on
}

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Need help with hotkey script

Post by mikeyww » 22 Jan 2023, 09:25

I cannot troubleshoot your specific game, but these are the tips, which include testing running as admin. viewtopic.php?f=7&t=11084. Some games block scripting. Search the forum for tips about your specific game.

The 80 is the timer frequency in milliseconds. The click will execute at that frequency. You can try different values. Since other things are happening with this script and other programs at the same time, the effect is never precise, or, well, not usually.

#IfWinActive can be used to define a window context for a hotkey. There is no point in adding it until you get the basic script working.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Need help with hotkey script

Post by DuckingQuack » 29 Jan 2023, 11:19

@mikeyww Is the state of "on" being toggled by the assignment in the period parameter?

Code: Select all

 Static on := False

Code: Select all

 on := !on
Also, is this the correct page for the documentation regarding the "Fat Arrow Function?" The section on this page does not seem to support the way you have it working, at least, it doesn't explain the syntax you used.
Best of Luck,
The Duck

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Need help with hotkey script

Post by mikeyww » 29 Jan 2023, 12:04

Hello,

Yes, you have cited the toggle correctly. A timer specifies the function object to call. A fat arrow function defines a simple function and returns the function object. Thus, a fat arrow function can be used in a SetTimer, because it returns the function object. My script confirms it.

The documentation for fat arrow function notes that specifying the function name is optional.

Just as with other function definitions, if parameters are not used, then () can be specified.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Need help with hotkey script

Post by DuckingQuack » 29 Jan 2023, 15:51

That’s outside my realm of understanding at the moment, but I’ll get there.
Best of Luck,
The Duck

Post Reply

Return to “Gaming Help (v1)”