Automate routine with Autohotkey in Steam ver

For me, the most tedious thing in mass construction is to choose the necessary material. Or every time, click on the button to remove the item. So I automated these two things with Autohotkey. If you spend a little time, it will be much easier and faster to build.

Autohotkey is a very lightweight scripting language for automation. Here you can download it (i use v1.1): https://www.autohotkey.com/

You need download it, install, reload, and now you can launch your scripts. To make a script, just make blank text file (rmb - new - text document), then change extension from "txt" to "ahk" and run it with code - that's it.

Code (copy-paste it in your ahk file and additional changes needed, explanations below):

#ifWinActive ahk_class SDL_app


!d::
MouseGetPos, xpos, ypos 

BlockInput, MouseMove 

MouseMove, 1911, 143, 0
Sleep 30
Send {LButton down}
Sleep, 20
Send {LButton up}
Sleep, 50

MouseMove, %xpos%, %ypos%, 0
Sleep 300
Send {RButton down}
Sleep, 20
Send {RButton up}
Sleep, 50

BlockInput, MouseMoveOff

Return


!l::
MouseGetPos, xpos, ypos 

BlockInput, MouseMove 

MouseMove, 1380, 250, 0
Sleep 30
Send {LButton down}
Sleep, 20
Send {LButton up}
Sleep, 50

Send {L}
Sleep, 20
Send {i}
Sleep, 20
Send {m}
Sleep, 20
Send {e}
Sleep, 20
Send {s}
Sleep, 20
Send {t}
Sleep, 20
Send {o}
Sleep, 20
Send {n}
Sleep, 20
Send {e}
Sleep, 20
Send {Space Down}
Sleep, 20
Send {Space Up}
Sleep, 20
Send {b}
Sleep, 20

MouseMove, 2030, 313, 0
Sleep 30
Send {LButton down}
Sleep, 20
Send {LButton up}
Sleep 50

MouseMove, %xpos%, %ypos%, 0

BlockInput, MouseMoveOff

Return


!j::
MouseGetPos, xpos, ypos 

BlockInput, MouseMove 

MouseMove, 1380, 250, 0
Sleep 30
Send {LButton down}
Sleep, 20
Send {LButton up}
Sleep, 50

Send {j}
Sleep, 20
Send {e}
Sleep, 20
Send {t}
Sleep, 20

Send {Space Down}
Sleep, 20
Send {Space Up}
Sleep, 20

Send {b}
Sleep, 20

MouseMove, 2030, 313, 0
Sleep 30
Send {LButton down}
Sleep, 20
Send {LButton up}
Sleep 50

MouseMove, %xpos%, %ypos%, 0

BlockInput, MouseMoveOff


Return


#ifWinActive

Explanations:

There 3 hotkeys, Alt+d - autodelete, Alt+l - choose "limestone blocks" and click "all", Alt+j - "jet blocks" and click "all"

!d::

Autodelete installed crafts - it clicks on the removal icon and returns the cursor back and close opened window

Alt+d - It is hotkey i define to run the code ("!" - alt, you can customize it: "^" - ctrl, "+" - shift) d - just d, so you can change to ^+r:: — "ctrl + shift + r"

MouseMove, 1911, 143, 0

where the script will move the mouse, we all have different monitors, and these numbers will be different, so you have to define your own. To do this, run script first, script icon will appear on taskbar, RMB and run "Window Spy". Window spy wall appear and you can see your mouse position numbers (x, y). You need to define your cursor position numbers. Run DF in windowed mode, hide your taskbar, fullscreen DF window, move the mouse cursor to the delete icon, change my numbers to yours. Save and reload script (RMB on taskbar icon - "reload this script"). If you play fullscreen, subtract from Y 20 (Your mouse position like 1620 107 - you need 1620 87).

!l:: and !j::

Moves the cursor to the entry point of the material, presses LMB, enters the name of the material, chooses "All". You also need to change the number of cursors (there two of it - input the name of the material and the button "all"). And of course change all the letters in the title of the material to the one you need.

P.S.

I locked mouse while the script is running, so that my random mouse movements do not stop it, but the lock only works if you run the script as administrator. If you run the script without administrator, it will work, but it cannot lock your mouse moves.

When you build, there’s one limitation - your mouse should be on the left side of the screen. If the mouse is in the right part, the input window will appear in the left, which breaks the whole script.

Posted Jan 16, 2023, 2:22 AM UTC · edited

44
cip43r•

Has anyone done this with a Logitech mouse or keyboard? I have the G642 mouse or something like that and recently saw that they also have a scripting feature now.

1

for code you can do way less lines like this. 24 lines of code becomes 2!!!

SetKeyDelay, 20

Send Limestone{Space}b

​

I would also look at this video so people don't need to hard code their mouse pos. great for those who no nothing about coding

https://www.youtube.com/watch?v=2o3EAhg9o3A&list=PLfHPAKSz_DJr0m08uwv2_X-uYFRVhSRuD&index=20

1
MixOldOP•

SetKeyDelay, 20

Send Limestone{Space}b

It's not just a matter of selecting material, it's a matter of not having to move the mouse back and forth a hundred times. I checked this piece - it works! Thanks)

1
MixOldOP•

Thanks to your comments, I figured out how to get around one restriction. The material input window appears on the right side of the screen, or on the left. My code only worked on the right, but now it works in any position. Yay)

1
ouroborus777•

Send doesn't seem to work with the latest Steam DF

1
MixOldOP•

Works for me, even without "run as admin". What is your task, maybe I can help you out. For example, this script works perfectly fine for me.

!s::			;### Sandstone
MouseGetPos, xpos, ypos 

BlockInput, MouseMove 

MouseMove, 1200, 250, 0
Sleep 50
Send {LButton Down}
Sleep 50
Send {LButton Up}
Sleep 50

SetKeyDelay, 30
Send Sandstone{Space}b

MouseMove, 2030, 313, 0
Sleep 50
Send {LButton Down}
Sleep 50
Send {LButton Up}
Sleep 50

MouseMove, %xpos%, %ypos%, 0
BlockInput, MouseMoveOff

Return
1
ouroborus777•

Turns out I had to restart Steam to get it to work. Thanks for taking a look at it, though.

2