[Tool] AutoHotkey scripts

@slippycheeze

Test failed. This makes script also work when you are using Grim Tools website -> because the tab in web browser start with “Grim Dawn”. However you can fix it with

SetTitleMatchMode, 3
#IfWinActive, Grim Dawn

The first line forces the window title to exactly match IfWinActive argument (not start with it)
That may have been the reason I ditched IfWinActive before

Haven’t tried anything yet but when I was browsing the internet for some code it seem like too much work/no guarantee it will work in the end.

However you can kinda use AHK scripts if you bind some keyboard key to gamepad button (in Steam Controller Configuration Legacy Keys submenu). Then it works like this

  1. you press some gamepad button
  2. it makes chosen keyboard key to be pressed
  3. Grim Dawn switches automatically from Gamepad mode to Mouse & Keyboard mode (wish these two modes could work together)
  4. And know you have to move the analog stick for Grim Dawn to go back to Gamepad mode again unless you don’t want your controller to work

That’s how Inquisitor Seal cast under your feet when using controller works

The easiest way to use M&K actions without modifying xinput and staying in gamepad mode would be a hardware converter like CronusMAX.
But surely you have to buy it first.

a) From my experience, event mode is way better for games (esp on slower pcs) than input.
Input is ofc faster, but its TOO fast (since it has no inherit delay, + it buffers).

using my script(s) in input mode, the game(s) often fails to recognize an action or modifier states get fubar.
eventmode increased stability of scripts alot plus you can set a global delay and presstime

b) in gd at least, you can send the keys in blind mode what reduces strain on the games i/o. that reduces the chances for stalling shift modifier eg when you use mouse + shift combo for hold position casting. (gd doesnt care when you use modifiers on action keys) eg shift-5 fires slot5 as 5 does.

c) mind to explain the reasons for your autoexec choices?
i often play with them and im curious about why you chose those.

#NoEnv
#SingleInstance Force
*#MaxHotkeysPerInterval 1000 *
#MaxThreadsPerHotkey 1
#KeyHistory 50

p.s
Setkeydelay, delay, pressduration
is crucial in messy situations (and individual dependent on machine specs)

yep, using always those in scripts, keep attention to the different formats/usages

clientstring = Grim Dawn

#If WinActive(clientstring)
#If
for hotkey part of the script and

IfWinActive, %clientstring%
{ }

for the timers etc.
combo together with mode 3

p.s use the build in windows spy to get the necessary information

LWin::
gosub, stoptimersandcounters
send {lwin}
sleep 50
Pause on
return

Its nifty because it sets the script on pause when you tab out via winkey in addition to suspend/ the stuff that is ex/included by
ifwinactive or #if winactive () etc.

Thanks a lot for the tips. I need more time to process them since I’m not so advanced.
Especially the configurable event mode seems very interesting since I may be able to remove all those ugly Sleeps from the code with it if I understand correctly.

btw Could you share some of your scripts for Grim Dawn (even for other game would be useful) so that I could learn from them?

[edit] The 80% of the script, for example Capslock hotkey

SetTitleMatchMode, 3

#IfWinActive, Grim Dawn

CapsLock::m

doesn’t work in the Event mode. Do you know what may be the reason (I checked various SetKeyDelay arguments and it didn’t help)?

hm, im not using capslock in my gd script , i just set

SetCapsLockState, AlwaysOff
SetNumLockState, AlwaysOn

to not get annoyed in and out of the game :slight_smile:

hm, just checked my tangledeep script:

*$CapsLock::
Send anykey
return

aka: its working in both ways (see *edit3), even with an active SetCapsLockState, AlwaysOff.
Important is that you either set the keyboardhook (for all stuff in the script) or put a leading $ in front of it, what activates the hook just for that hotkey

edit3:

aboves scriplet is different from capslock::anykey in the way, that it repeats sending the key while capslock is held down. with latter version, it just sends the key 1x, even if you keep holding capslock

edit1:

*Capslock::m*  ;or any key that has a function in gd

is working flawlessly here. (reason see edit 2)

edit2:

think i know why it may be not working for you:
you should/need to set the keyboardhooks in the autoexec part of the script (unless you want that its able to trigger its own hotkeys what in most cases is unwanted behaviour)
for some stuff its done atomatically by AHK, but better safe.

( the input sendmode automatically installs the hook, thats why it worked for you in input mode )

means:

#InstallMouseHook
#InstallKeybdHook

makes life easier in more then one way for ahk.

maybe, but i yet hesitate, b/c most are WIP (aka a mess) and id need to remove all my selfquestioning comments first :slight_smile:

apropos comment: make a habit of it and comment each important line. i do so but not constantly, so now im back, checking old scripts and wondering about some codelines and why i used it that way :wink:

Sometimes I do not want to have an Automatic camera (following your character).
So I changed your line

if xposxpos + yposypos < 40000 ;<200 pix from center -> no rotation

from 40000 to 400000.

This way the camera only rotates when the cursor is on the edges of the screen.
-> build in automated camera rotation on demand, via your left click :slight_smile:

2 Likes

Nice modificattion, I like it :slight_smile:
So this means the radius is sqrt(10) ~ 3 times bigger, about 600 pixels.
Another thing I’ve just thought of is that the radius is adjusted to my small resolution 1280 x 720 (for fps).
Most people probably play in Full HD.
I think the radius should be configurable in .ini config file and expressed in % of the height of the screen so that the behavior of the script it’s not dependent on the resolution

1 Like

Running 2 scripts right now.
One is the modified camera.
The other is a variant of “seal under your feet”.

In the latter you wrote a header that apparently allows ultra-mouse speed when auto-moving to screen center.
When I’m running the 2 scripts simultaneously, that ultra-speed is gone.
Any clues…?

Please merge the 2 scripts and see if the problem persists. I don’t support running 2 scripts simultaneously :rofl:
Inquisitor Seal cast under your feet when using mouse and keyboard
I use the header from this code in every script, the lines with Hooks are commented and thus not working

Thing is, the camera-script has a loop for LMB, and the seal-script has an added loop for the RMB.
Been trying things like this before in only one script.
The triggers (when mouse button pressed) were close to zero reliable.
Seemed like the two loops blocked each other or so.

Send me these scripts or this one merged script and I’ll try to fix it/merge them. PM or here. 2 scripts simultaneously is just asking for problems.

Know however that holding Left Click + Right Click in Grim Dawn just doesn’t work - these two keys block each other and I could not get them to work. I even tried setting Right click to move/clear/attack and nothing worked as I wanted it to. That’s why I’m sometimes holding Space + Left Click instead of Left Click + Right Click because it just doesn’t work in Grim Dawn and it’s not script fault. This may or may not be connected to the problems you were having. Just saying. I tried replacing Space in my scripts with Right click having Left Click loop at the same time and I couldn’t despite trying to do it in like a million ways.

yea, it gets complicated with mousekeys. think i spend quite some time trying to fnd an optimal way to use both bottons w/o wasting it for just “move to”.

using this currently:

Rbutton::
setbatchlines, -1
if (stopped = 0) ;remarks here
	{
	send {blind}{shift up}
	sleep, 120 ;cast gcd
	send {blind}6 ;attack/spell
	gosub, quickbar2_0 ;some attack/spell from bar2
	}
	startTime_RB := A_TickCount 
    KeyWait, Rbutton, U T0.3 
    PressDuration_RB := A_TickCount-startTime_RB 
	if (PressDuration_RB < 280) ;if the key was pressed down for less than 280ms just behave as normal
		{
		setbatchlines, 20ms  
		return  ;
		}
    else 
		{
			While (GetKeyState("RButton", "p") || GetKeyState("LButton", "p")) && !GetKeyState("SHIFT", "p")
				{
					send {blind}{a down} ;move to
				}
			send {blind}{a up}
		}
		setbatchlines, 20ms
	return

since lbutton walk is annoying when the cursor hits an attackable object but you need to get out of a mess this one moves the char (a = bound to move ingame) after you keep/kept pressing R- or Lmouse for more than a configurable period. (for me 280 is quite ideal).
Its important to note, that the rbutton isnt hidden (even cant be hidden) from the game, so the first thing the game does when you press rbutton while the scrit is running, the game executes the stuff thats currently bound to rbutton (for me some attack/spell). then your other stuff form script gets processed

i had an other (better, aka flawlessly working move/attack/hold pos) solution for lbutton, but got in conflict when you worked in the ui, eg selling or moving items.
since im not aware yet of a proper detection of ingame situation (mho pixel/image search doesnt work in fullscreen) and direct memory reading is atm out of my scope, this one does quite well.

also had one of the sidebuttons as ‘f’ solution that forced the mousebutton to move, but just got myself stalled in messy situations because i couldnt decide with method to use - so i reduced it to this one method. :slight_smile:

p.s did you get the capslock working in event mode?

p.p.s. if anyone has an idea for a reliable detection of ingame scenario (are ui elements open, or are we in combat, etc) id be glad to hear. my quite bold lowtech solution currently is to stop all fancy stuff in combination with casting portal (+ added ‘are we sure we want this’ delay because i hated it to accidently destroy an existing portal)

you shoud be able to autodetect the resolutoin quite easily inside AHK with something like

WinGetPos, X, Y, Width, Height, %clientstring%

but thats for windowed or windowed fullsceen.

for fullscreen stuff mho reading the games ini should work. (aka plan b)
so you can automaticaly calculate stuff for the camera, etc

another really small one but one of my favorite ‘invention’ :slight_smile:
*phoenix glyph enchant required

^Lbutton::  ;horizontal rocketjump aka retreat on ctrl-L
	sleep, 100 ;needed time to face in opposite direction
	send {blind}9 ;phoenix rise
 return

^Rbutton::  ;horizontal rocketjump aka retreat on ctrl-R
	sleep, 100 ;needed time to face in opposite direction
	send {blind}9 ;phoenix rise
 return

I don’t really understand how you use it and why you want to face opposite direction. It reminds me


of reversed disengagement movement skill function I’ve written

1 Like

its just in case you forgot to target, usually the cursor is already there where you dont want to be, but in the case you activate it and then see o shit., ill land in a wall, you have to fix the positioning. actually i dont want to lose the aim on my targets while disengaging, thats why “opposite”. so the sleep is just there to have time to correct.
i didnt want any automated positioning here, because its too situational and too dangerous mho.

as usual there are million ways to rome whith ahk. personally i instantly felt comortable with it, (mb due to too much quake? :slight_smile: )

1 Like