[Tool] AutoHotkey scripts

Not only resolution but also UI Scale dependent :slight_smile:

Oh dear. Nice idea though!

Level 60 so I could finally farm Loxmere for my first 2 frostblades. He sometimes managed to take all my buffs down so I needed a macro to cast them back quickly (charge away, use macro and shadow strike back to the fight)

r::
    Send {t} ;switches quickbar
    Sleep, 300

    Loop, 5
    {
        Send {%A_Index%}
        Sleep, 300
    }
    
    Send {t}
Return

Also good after restarting the game. No need to constantly recast the buffs when restarting the game when farming some specific monster.

Cool! Whats A_Index?
And is 0,3s of sleep necessary after quickbar switch?

Probably not necessary, I just didn’t want to spend more time finding optimal values.
When you’re using this Loop, A_Index variable holds current number of iteration. It’s from AHK, not created by me. It goes through 1, 2, 3, 4 and 5

aaah ! really cool.

@ncience
Hey, how would you solve the following problem?

I have timer spamming a button and when I alt + tab,
alt get stuck because of it despite having if (WinActive) check before sending the press.

I could unstuck manually easily (I have an always running timer that is responsible for transitioning between active and nonactive grim dawn states anyway), I remember doing it in Diablo 3 but maybe you can figure out a smarter way/know some magic. Sorry for so little details.

For some reason I didn’t have this problems in previous versions of GDAutocaster :thinking:

trying to understand the scenario by rephrasing on own words
a) a timer is running spamming some button
b) then you alt-tab out of the game
c) the timer continues with its work? (i dont exactly know what you mean
with alt get stuck ? )

before that, is blindly add:

  • Thread, NoTimers, true <- prevents your current thread beeing interrupted by any timer
  • Pause On, 1 <- pauses all threads running below the current thread (so the current thread can finish its actions)

maybe on of them helps?

in any case, if your if statement embraces the timers action, it definitely should not execute.
hint: after you alt-tab, is grim dawn not active or just minimized ?

Yes, I don’t turn off the timer, it spams the button (this is intended)
[but it has IfWinActive protection so that there’s no Send while not in game]
then I alt + tab
and after that when I’m in Windows you can see that Alt is pressed down and you need to press Alt to unstuck it
also when you alt tab you can here this specific Windows sound once of weird button press

I guess you could simplify it by (but I didn’t test if it also makes ‘alt’ stuck)

SetTimer, f, 100

f()
{
    if(WinActive("Grim Dawn"))
        send {1}
}

EDIT yes, it does, this code makes ALT stuck after ALT + TAB

Oh I see you wrote some things to check out, gonna read them now

no clue atm what this causes, but you could intercept alt-tab with ahk and do an alt-tab send by ahk (i do that with the win button, since ahk releases the modifier key after send, windows should see a released alt key.
After i understand the problem, i doubt any of the 2 points above are of help here, but theyre good to know nonetheless :slight_smile:

Summary

LWin::
gosub, stoptimersandcounters
sleep 200
send {lwin}
sleep 50
scriptpaused = 1
Pause On, 1
Suspend, On
gosub, checkpauseorsuspendloop
return

1 Like

Sorry, I run just this code

SendMode Input
#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 1000 
#MaxThreadsPerHotkey 1
#KeyHistory 50
#persistent

SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 3

SetTimer, f, 100

f()
{
    if(WinActive("Grim Dawn"))
        send {1}
}

and it doesn’t stuck the ALT key so it’s something else in my code (most probably the loop that’s governing the transition between in-game and minimized and vice versa)

does it also happen with a different send mode? (modifier keys are handled differently per mode)

aka your testscript is using event (default) and afaik your gamescript is using input method?

edit: my script does something similar, having a saves backup timer running permanently, and only activating when the game is active. i tried with alt-tab out of the game and everything is fine.

are you 100% sure that your if statements are working? mb just use normal labels for the timer routine instead of function? shoudnt make a difference, but who knows.

edit2: do you maybe have anywhere a send that is executed too often in a loop w/o a sleep between? the functionality is there but it may cause some overflows so maybe windows gets flooded from the buffer?

I changed the sendmode by deleting

SendMode Input

like you told me many times in this thread as far as I remember :rofl:
and it fixed the problem! Thanks

Now I need to test if all the stuff is working properly but it seems so at the first glance
Well I needed to change all

MouseMove, x, y

to

MouseMove, x, y, 0

because in input mode cursor is moved instantly by default and in other modes you need to give them 0 argument for that.

1 Like

Input mode is superior on paper, but its different in reality, esp when only one application thats running fullscreen and eats majority of system ressources is the target.

the superior speed is often rather a disadvantage, because its just too fast. if you forget a sleep somehwere eg while (condition) , send somestuff, return you have an instant mess. or some games just dont recognize a press because the key gets too fast released.
same goes for its buffering property, the buffering is often rather unwanted in games (and its my nr1. suspect for the alt-tab problem).
anyway, you can switch between the modes in your script at any time/place. if you have stuff youd prefer with input method, just switch to input mode and switch back after.

1 Like

Could you tell me if you have ever had such problem in your programs?:

You launch it and not every hotkey is working but some does, you press it and now everything is working fine from that moment on.
I had it basically from the beginning in various version of the program.

Sometimes I had to hold Left Click for all the hotkeys to start working, now I sometimes have to 2xTab (which is for suspending keys but I’m pretty sure it’s not logic mistake [I mean incorrectly managing suspension of hotkeys]).

I’m just wondering if it’s my fault or it’s just some AHK thing.

Also, I added

#HotkeyModifierTimeout -1

Based on the documentation, it seems to be good stuff.

1 Like

Watch out.

SetTitleMatchMode, 3
if (WinActive("Grim Dawn")

works not only in-game but also if your active window is a folder called “Grim Dawn” :man_facepalming:
It really bamboozled me.

same goes for browser tabs :slight_smile: not sure if i mentioned it somewhere above, but you can also/additionally ‘filter’ for the name and/or path the running .exe has to have.

you do that via the WinTitle ahk_exe parameter

Also, I added

#HotkeyModifierTimeout -1

Based on the documentation, it seems to be good stuff.

  • thats why you use {blind} for sends that doesnt need a certain modifier state (GD doesnt care if you send 5 or shift-5, since it reads the raw keycode for action bindings), that frees ahk to care for setting a modifier state

  • only when your not using keyboard or mousehooks. But since the hooks are recommened and even activated by certain stuff you mostly dont need aboves directive. (but good to know anyway)

i strongly recommend putting one of these

#InstallMouseHook
#InstallKeybdHook
#UseHook

in the autoexec part of your scripts for even mode based sends. (its just ~ +500kb more memory)

i didnt have that behaviour yet in any of my scripts, i think its related to not using the hook. try it with activated hooks and see if it solves the problem. ( -it could also an interference with other software that operates on same level, - startorder may be a thing ,- rights of the user runing ahk matters too )

Edit: if your interested, i share my idea/solution for a smart(er) auto hiding of items during combat. i think the current solution is to temp hold a button to temp hide the items?

Sure. Do you mean some nice way to detect that you’re in combat?
Defining skills/keys you use only in combat and making them hide stuff?

its a bit more complicated, but basically, yes. ill pin it down here tomorrow or the next days