[Tool] AutoHotkey scripts

Been using this script as a draft for my SBoE spam.
I changed the 2nd “Click” (in the while loop) to a “Click Down”.
This way there is actually a click down when you hold LMB - instead of a machine gun click (which is responsible for clunkiness when dragging the map e.g.)

1 Like

Remember you can always use something like
Tab::Suspend
if you want standard behavior outside combat

you can also make middle button do this thing, I mean
MButton::
[rest of the code the same]

I just remembered why I needed “Machine Gun Left Click” - to pick up stuff on the ground without clicking like a mad man!

Use this code, it will be better for your situation (without “Click, down” in a loop). Cleaner but without machine gun picking up items.

~LButton::
    KeyWait, LButton, T0.2
    if ErrorLevel
    {
        while GetKeyState("LButton", "P")
        {
            Send {7} ;key responsible for Storm Box
            Sleep, 25
        }
    }
Return

Also the sleep time can be longer, like 100 ms insead of 20 ms, in your case. I needed 25 ms for fluent movement in the ‘machine gun’ version but for just casting Storm Box in a loop when left click is hold normally not spammed you can easy get by with 100 - 200 ms I think. Doesn’t make a difference probably, just saying in case some performance problems.

Inquisitor Seal cast under your feet when using controller

shift := 0
1::
    WinGetActiveStats, Title, Width, Height, X, Y
    MouseMove, shift + Width/2, Height/2
    shift := shift ^ 1
    Sleep, 10
    Send {Click, right}
Return

One guy didn’t like the fact that the seal is cast in front of your character if using gamepad.
The solution is to:

  1. bind Inquisitor Seal to Right click in Mouse & Keyboard mode
  2. bind ‘1’ to some controller key using Steam Configuration (you need to access ‘Legacy Keys’ menu)
  3. run the script
  4. unfortunately you need to move analog stick a bit after every such cast to go back to controller mode from mouse mode

More info here: A self-target action for Controller

1 Like

Man, I like that.
Can´t I just use this one If I ´m playing with Mouse & Keyboard as well?

On controller mode, any way to auto-move my character to perhaps nearest monster/object the character is facing whenever I use a default weapon attack skill?

Was hoping something similar to how movement skills like Blitz and SS works where they auto-target. Playing a melee char on the controller is such a subpar experience.

@Kuma Yeah this sucks man. That’s the reason why I’ve switched to M&K to play melee Primal Strike. The guy doesn’t approach enemies and sometimes swings in the air whereas with M&K he approaches automatically and you never swing in the air. Unfortunately I cannot do anything about since I don’t read the game’s memory and I cannot read the position of the monster you are targetting with a controller (the cursor is hidden and is in a completely different place then)

@klasperstanze
Inquisitor Seal cast under your feet when using mouse and keyboard

SendMode Input
;#UseHook
#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 1000 
#MaxThreadsPerHotkey 1
#KeyHistory 50
;#InstallKeybdHook
;#InstallMouseHook
SetWorkingDir %A_ScriptDir%

s::
    WinGetActiveStats, Title, Width, Height, X, Y
    MouseGetPos, xpos, ypos
    BlockInput, MouseMove
    MouseMove, Width/2, Height/2
    Sleep 10 ;Sleep, 25 lowered it, needs testing in specific case
    Send {3}
    ;Sleep, 25 not needed in most cases, test it
    MouseMove, xpos, ypos
    BlockInput, MouseMoveOff
Return

A few remarks:

  1. I included my settings in the beginning since not all scripts work well if I mess them up
  2. s:: -> the key you’d like to cast the seal with
  3. Send {3} -> bind this key to da Seal
  4. The keys in 2) and 3) should be different. I can make it work when it’s one and the same key but it has some minor problems so I would prefer these to be different. But if you really need this to be one key, tell me
3 Likes

That´s just great! Works perfectly! Thanks again!

Nice!
But shouldn´t the 1st line of the top script do the same? Anyway, I had to delete that “if winactive…” in order to make the script work.

You can replace that entire loop with the following line:

#if WinActive("Grim Dawn")

…which is documented here: https://www.autohotkey.com/docs/commands/_If.htm

That is the general syntax for “contextual” hotkey stuff, as in, “only activate the hotkey when a specific application is active.”

It’ll respond instantly, though, instead of taking a whole second to toggle like your loop.

1 Like

Thanks. I know this of course and tested it in some previous program and it didn’t work that’s why I made up this Loop stuff glad it’s not needed. It must have not worked due to some silly mistake. I deleted the post so that it doesn’t confuse people.

[edit] No, it sometimes doesn’t work. When I configure keys to rotate, they don’t work in-game with this directive and work without it. When I configure scroll to rotate, it works (and keys work after scrolling for one time). Very weird behaviour that’s why I’m going back to Loop. I really don’t understand it. And I saw messages on some forums with people having the same problem.

Primal Strike + Savagery + movement on Left Click

~LButton::
    KeyWait, LButton, T0.2
    if ErrorLevel
    {
        while GetKeyState("LButton", "P")
        {
            Send {7} ;key Savagery is bound to
            Sleep, 1900 ;delay to Savagery so that we use it just to keep the buff up
        }
    }
Return

The number of Primal Stack attacks barely changes since the animation of Savagery after Primal Strike is very short. Especially with high attack speed.

1 Like

Niiice idea! Sort of that can also be used for warlords who chose to use cadence and rf at the same time. Its always a pita doing this manually.

1 Like

Don’t know if you’re using the seal macro at the moment but it still works for me if I remove the second sleep and lower the first sleep from 25 to 10 (less cursor flickering and more fluid).

I do. Gonna try it!

Lmao the script turns on not only when Grim Dawn is active but also when i.e. I have a tab opened in Firefox “Grim Dawn Item Databse” (Grim Tools).

Tried it. Flicker is not observable anymore. But sometimes in combat the script fails to hit the middle of the screen. Cannot really say why. Not too big of an issue though.

This happens when the sleep is too low, especially in the middle of the combat with lower fps. Just need to find the lowest value that doesn’t cause that :slight_smile:

Reversed Disengagement Movement Skill (Rune of Ishtak’s Mercy)

RButton::
    WinGetActiveStats, Title, Width, Height, X, Y
    MouseGetPos, xpos, ypos 
    MouseMove, Width-xpos, Height-ypos 
    Sleep, 30
    Send {4}
    MouseMove, xpos, ypos
Return

You move in the direction of the cursor instead of backwards as it is by default.

2 Likes

Absolutely great! What an idea!

Hey, I´m currently struggling with something:
As long as my LMB is pressed, I want to apply ABB every 4 seconds and 2 other buffs every 30 seconds.
I cannot make two separate loops for that, as far as I can see - since the 1st loop never ends. Any quick suggestions? Would go for a counter being checked by modulo 30, but idk how to write this in “script”.

Better autocasting of multiple skills (frequencies, delays)

I’ve written such stuff for Diablo 3 but the code was very complicated (the loop was external always working in the background, different skills had different frequencies, you could pause them, toggle some of the skills etc) and I used the modulo (it’s clean and great for minimizing number of threads). It doesn’t need to be complicated though

Let’s assume the step for Modulo is 100 ms (instead of 1000 ms) so that we can set the frequencies to 1300 ms, 2700 ms etc instead of just 1, 2, 3, 4 s (can be changed to bigger 200, 500, 1000 ms if there are some performance issues)

Now we want choose the big number we are going to divide to check whether it’s time to use our skills. You want your skills to be cast 1) every 40 x 100 ms 2) every 300 x 100 ms. We want to choose a number that is divisible buy both 40 and 300. Let’s take the Lowest Common Multiple

LCM(40, 300) = 600
If we choose for example 3 skills with 1.3 s, 2.5 s and 10 s (13 x 100ms , 25 x 100 ms, 100 x 100 ms)
we would take
LCM(13, 25, 100) = 1300

Testing code for you to test

; my settings, highly recommend them for your scripts, they make a difference
SendMode Input
#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 1000 
#MaxThreadsPerHotkey 1
#KeyHistory 50
SetWorkingDir %A_ScriptDir%

~*LButton::       ; * makes it work with Shift and other modifiers
    KeyWait, LButton, T0.2
    if ErrorLevel
    {
        counter := 0 ;0 for the first skill to be casted ASAP
                     ;1 for the first skill to be casted later
                     
        while GetKeyState("LButton", "P")
        {
            if !Mod(counter, 30) ;every 30 x 100 ms
                send {1}
            
            if !Mod(counter - 5, 30) ;every 30 x 100 ms, -5 for the 2th skill to be cast 0.5s later
                send {2}         ; to avoid skill conflict when you just started holding The Left Click
                
            if GetKeyState("Shift", "P") and !Mod(counter - 10, 30) ;combining with Shift for fun
                send {3}              ;every 30 x 100 ms, -10 for the 3th skill to be cast 1s later 
                                     ; to avoid conflict when you just started holding Left Click
                
            Sleep, 100 ; 100 ms instead of 1s for more freedom
            counter := Mod(counter + 1, 6000) ; in this example it could be 30 because
                                       ;  LCM(30, 30, 30) = 30 or any multiple of 30 like 6000
        }
    }
Return

The code doing exactly what you wanted (worse for testing, only changed fragment)

if !Mod(counter, 40) ;every 40 x 100 ms
                    send {1}
                
                if !Mod(counter - 5, 300) ;every 300 x 100 ms, -5 for the 2th skill to be cast 0.5s later
                    send {2}         ; to avoid skill conflict when you just started holding The Left Click
                    
                if !Mod(counter - 10, 300) 
                    send {3}              ;every 300 x 100 ms, -10 for the 3th skill to be cast 1s later 
                                         ; to avoid conflict when you just started holding Left Click
                    
                Sleep, 100 ; 100 ms instead of 1s for more freedom
                counter := Mod(counter + 1, 600) ; LCM(40, 300, 300) = 600
                                                          ; or any multiple of 600 i.e 40 x 300 x 300

The problem is in Grim Dawn when you want to cast 2-3 skills at the same time sometimes not all of them fire (the skills interrupt each other). You know, when you have your skill to be casted every 30s and it for some reason it’s not casted and you have to wait another 30s? You have a problem. My workaround for that has been trying to cast skills more often than needed (for example I would try to cast Totem/Wind Devil every 1s not every 5s) but the workaround has to be always tailored to the specific case. In this code I added time shifts for 2th, 3rd skills (counter -5, counter - 10) to prevent this when you start holding the Left Click. This could be combined with higher frequencies to be sure, for example trying to cast skills every 15 seconds instead of 30 seconds. You could probably improve the code so that there’s never conflict between skills but the code complication would be far greater than the benefits. You could make the counter global, to change the behavior a little bit. You could make the buffs to fire only once etc.

Another little problem is these times probably won’t be precise. What I mean is for example when the loop Sleep is 100 ms, the loop step will probably take longer than 100 ms (? I don’t know for sure though)

There’s also a possibility to have external loop working constantly in the background and you only “toggling” it with a hotkey, not having to hold a button if needed.

Tweak the code to your liking, it has lots of freedom and many ways of adjusting autocasting so that it plays very well. Almost anything can be achieved in Autohotkey but sometimes it takes me weeks to figure out some bugs/behaviors. I have lots of fun writing and testing these scripts so write if you have any problems. And as it’s always the case I’ve learnt something and got the code I’ll use myself.

Video of Testing Code (at first we don’t hold shift so Devouring Swarm doesn’t fire)

PS Some new stuff

dual mode Left Click Hold
(cast some skills when you just hold Left Click and some more skills when you additionaly hold Shift)

~*LButton:: ; ~ means Left Click still clicks, * means it works with Shift, Ctrl etc
    KeyWait, LButton, T0.2
    if ErrorLevel
    {
        while GetKeyState("LButton", "P")
        {
            Send {7} ;key for Wind Devil
            
            if GetKeyState("Shift", "P") ;When Shift pressed do something else as well
                Send {8} ;key responsible for War Cry/Wendigo Totem which we only 
                
            Sleep, 500 ; sleep time low to cast skills with very little delay
        }
    }
Return

suspending only selected hotkeys with a hotkey (not all of them with Suspend function):

q::
    Hotkey, ~*LButton, toggle
    Hotkey, ~*RButton, toggle
Return