Jump to content

Keyboard / Autohotkey Scripts (Autorun and such)


Gazz

Recommended Posts

While the UI in the game is admittedly very polished for an "alpha", it still doesn't have a lot of the convenience features that would usually be added in the "polishing" phase.

 

Keyboard scripts can help overcome some alpha UI problems like having to hold down a key for many minutes or mashing a particular key a whole damn lot. (I'm looking at you, E!)

 

 

  1. Autohotkey Installation
     
    Download and install Autohotkey.
     
     
  2. Script Installation
     
    Autohotkey scripts are text files with the .AHK extension.
     
    Create a text file, rename it to SomeNameILikeALot.AHK, and copy the "code" content from some example script here into the file.
     
    Now you can double click that file and the script will be active.
     
    If this header line
    #IfWinActive, 7 Days To Die

    is present at the top of the file, this script will only be active when the 7DTD game is the "active" window.
    (Look, it's so it doesn't mess with your text input if you're writing forum posts...)
     
     
    It is possible to wrap such a script into an executable but I choose not to do this.
    I wouldn't want to run EXE that I got from some random internet person.
    There's not a lot of harm you can do with a text file...
     
     

  3. Script Organisation
     
    You can put several functions into one file (easier to manage / start) but you can just as well make several smaller files to activate / try different functions.
     
     
  4. OMG you're writing a bot!
     
    Sigh. No.
    Such a script can not react to the game environment and it doesn't even know which UI windows you have open in the game.
    Scripts are dumb.
    They can perform simple and repetitive functions but they do nothing you couldn't do manually.
     
     
  5. Hey, can you write a tutorial for that?
     
    No.
    The Autohotkey forum is full of them. Go read.
     
     
  6. But if there is no tutorial (I already said that there are tutorials, dammit!) how do I change the keys?
     
    Those are text files. If there is Tab written and you want the thing to work on pressing "o", replace "Tab" with o.

 


This script does several things that I found stressful or fiddly.

 

The mouse click positions are for a 1440 x 900 resolution!

If you run a different resolution they won't work for you. Either use Autohotkey's included Auto Script Recorder to find these positions or wait for a Smart Person™ to do it for you.

 

  • Tab : Autorun
     
    The script sets the "W" key to a held down state. Simple as that.
    By pressing W manually you reset the state to down/up so autorun is back off.
    Really simple.
     
     
  • Shift + Mouse 5 : Mining / Logging
     
    Holds down LMB and "e".
     
    The shovel keeps swinging and every material that drops into the world is sucked up into your inventory.
    Just move and point.
     
    If you press LMB, only the Auto-pickup remains functional.
    That, too, is useful for more specific / semi-auto mining.
     
     
  • Shift + Mouse 4 : Autofire for the E key
     
    When I traipse around the desert, picking up stuff, I don't want to be hammering e.
     
    If you want to open a container, this obviously won't work but... the "e" key that you would open a container with also disables autofire.
     
     
  • Q : Switch weapon / tool set
     
    Switches toolbelt items 1-4 with the inventory slots right above them.
    I use a lot of tools / materials when building and it's bothersome to keep slots reserved for weapons in case of... zombie.
     
     
  • Shift +Q : Switch medical / food / water
     
    I normally keep Painkillers / Bandages in slots 8/9 and I switch those with food and water as needed.
     
    With this script I can switch rather quickly and it sets the active tool to "9", which is water... which I use more often and occasionally for an endurance boost.

 

 

#IfWinActive, 7 Days To Die

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

; Tab is autorun. W to stop.
Tab::
Send {w up}{w down}
return


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

;Shift + Mouse button 5 locks down LMB for larger mining projects.
;Simply press LMB to stop.
+XButton2::
Send {e up}{e down}
Click up left
sleep ,10
Click down left
return


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

;Shift + Mouse button 4 is autofire for the E key when I traipse around the desert, picking up stuff.
;E to stop.
+XButton1::
Loop 
{ 
	Send, e
	Sleep, 50
	GetKeyState, VKeyState, e, P 
	if VKeyState = D 
		break 
} 
return


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

;Q  to switch "weapon sets", slots 1-4
q::
;toolbar,  9 slots, 370,855 - 1070,855        .370.457.545.632.720.807.895.982.1070.
;inventory bottom row, 9 slots,  370,710 - 1070,710

;a sleep time of 100 barely worked for me. 80 started to malfunction. With lag, assume higher delays. BE GENEROUS.
Send i
sleep ,200
MouseClick, left, 370,855 ,1,0
sleep ,200
MouseClick, left, 370,710 ,1,0
sleep ,200
MouseClick, left, 370,855 ,1,0

sleep ,200
MouseClick, left, 457,855 ,1,0
sleep ,200
MouseClick, left, 457,710 ,1,0
sleep ,200
MouseClick, left, 457,855 ,1,0

sleep ,200
MouseClick, left, 545,855 ,1,0
sleep ,200
MouseClick, left, 545,710 ,1,0
sleep ,200
MouseClick, left, 545,855 ,1,0

sleep ,200
MouseClick, left, 632,855 ,1,0
sleep ,200
MouseClick, left, 632,710 ,1,0
sleep ,200
MouseClick, left, 632,855 ,1,0
sleep ,80
Send i

sleep ,80
send 1
return


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

;Shift-Q: switch food / water in slots 8/9
+q::
;toolbar,  9 slots, 370,855 - 1070,855        .370.457.545.632.720.807.895.982.1070.
;inventory bottom row, 9 slots,  370,710 - 1070,710

Send i
sleep ,200
MouseClick, left, 982,855 ,1,0
sleep ,200
MouseClick, left, 982,710 ,1,0
sleep ,200
MouseClick, left, 982,855 ,1,0

sleep ,200
MouseClick, left, 1070,855 ,1,0
sleep ,200
MouseClick, left, 1070,710 ,1,0
sleep ,200
MouseClick, left, 1070,855 ,1,0
sleep ,80
sleep ,80
send i
sleep ,80
send 9

Link to comment
Share on other sites

  • 3 months later...

After using and refining this for a considerable time (and a brief adventure with EAC going nazi), this is what I found useful in the long run.

 

 

#IfWinActive,7 Days To Die
;sendmode play  ;this was required to make things sort-of-work during EAC's delusion of grandeur

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Shift + Mouse button 5 locks down LMB for larger mining projects.
;Simply press LMB to stop.
+XButton2::
Send {e up}{e down}
Click up left
sleep ,10
Click down left
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Shift + Mouse button 4 is autofire for the E key when I traipse around the desert, picking up stuff.
;E to stop.
+XButton1::
Loop 
{ 
	GetKeyState, VKeyState, RButton, P 
	if VKeyState = D 
		Send, e
	Sleep, 50
	GetKeyState, VKeyState, e, P 
	if VKeyState = D 
		break 
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Ctrl + B,  autofire for RMB,  used for large scale planting
;RMB to stop.
^b::
Loop 
{ 
	Click right
	Sleep, 150
	GetKeyState, VKeyState, RButton, P 
	if VKeyState = D 
		break 
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Connection script, if the server is full or decides to play games with me
PgUp::
Loop 
{ 
	GetKeyState, VKeyState, PgUp, P 
	if VKeyState = U
		break 

		MouseClick, left,  785,  400
		Sleep, 1200
		MouseClick, left,  1200,  833
		Sleep, 1200
	MouseClick, left,  1001,  479
		Sleep, 2000
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Toggle Autorun
; Press SHIFT afterwards to lower the speed to autowalk. MButton will then switch back to autorun.
*MButton::
	GetKeyState, VKeyState, Shift
	if VKeyState = D
	{
		Send {w up}{shift up}
	} else {
		Send {w down}{shift down}
	}
		return
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Removing unwanted items from inventory or opened containers is a lot of work in this game. So...
;Q: drop item from INVENTORY / CONTAINER
; drop position left of inventory:   MouseClick, left,  410,  572

q::
MouseGetPos, StartX, StartY
MouseClick, left,  StartX,  StartY
Send, q
Sleep, 150
MouseMove, 410, 572,0
MouseClick, left,  410,  572
Sleep, 5
MouseClick, left,  410,  572
MouseMove, StartX, StartY,0
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;t   Loot container fill
; Used this for a while to put a SINGLE item in a container but it's of limited overall use. I commented it out. *shrug*

;t::
;	GetKeyState, VKeyState, NumpadDiv, P 
;	if VKeyState = U
;		{ 
;		Send, t
;		return
;		} 
;	else		
;		{ 
;		Send, e
;		Sleep, 600
;		MouseClick, left,  744,  489
;		Sleep, 250
;		MouseClick, right,  784,  198
;		Sleep, 250
;		MouseClick, left,  758,  483
;		Sleep, 250
;		Send, e
;		} 
;return

Link to comment
Share on other sites

One question though, how NAZI is EAC about these scripts?

Not at all.

There was a week or two when it was introduced when it tried to block everything and I had to trick my way past that.

 

 

Now, everything works normally, including GetKeyState, which is important because it tells you if a key is physically pressed down or if Windows thinks that it is pressed down.

 

I use the latter for Autorun.

The Autorun function locks down SHIFT so when I want AutoWALK (regen stamina) I tap SHIFT and it releases the key. Simple.

If I want to run again, I press MButton.

That checks for the "virtual" state of SHIFT and if depressed, it engages Autorun again. Otherwise it stops, which is the same as pressing SHIFT and W manually.

 

 

GetKeyState has many uses.

For instance, I use it as a "trigger" for the auto-pickup loop. Only when the RMB is held, it fires a stream of "E" at the game.

This way I can even loot containers (bird nests =) while the function is engaged.

I just tap RMB, it opens the container. Use "R" to loot. Move on.

Without that I'd have to dis- and re-enable the auto-pickup everytime I loot a container - or open the inventory!

 

 

Autohotkey doesn't let you create very smart scripts - but you can do some elegant ones. =)

Link to comment
Share on other sites

  • 2 weeks later...

Another update:

 

Now that it happened TWICE that I nodded off (just for a few winks, honest!) and my toon starved to death (meaning wellness = 30), I took... measures.

 

 

The first one is "simple". An AFK or screen saver function.

Be it the kids demanding attention right now, work interrupting, or just a long list of "quick" chores that keeps getting longer.

Sometimes you just leave the game unattended.

 

Now if you start this function and if you haven't touched keyboard or mouse for 55-65 minutes, it terminates the game, logging you out.

This is about the time you can stand around ingame with full food/water bars without losing wellness.

 

 

 

The 2nd is what I use for long-term crafting.

Every few minutes it tries to consume food/water. Since you can't overfill, it doesn't matter that it tries to do so without knowing if it's necessary. (it's just a dumb script =)

 

 

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;CTRL-g,  AFK guard
^g::
	SoundBeep, 800
Minutes := 60000
Loop
{ 
	Sleep, 10 * Minutes
	SoundBeep, 800

	;Check if there has been no physical user input for...
	if (A_TimeIdlePhysical > 55 * Minutes)
		{ 
		Send {Alt down}{F4}{Alt up}
		exit
		} 
} 
return


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Hold down END to keep eating/drinking while supplies last
End::
Minutes := 60000
Loop 
{ 
	GetKeyState, VKeyState, End, P 
	if VKeyState = U 
		break

	Send, 4
	Sleep, 3000

	GetKeyState, VKeyState, End, P 
	if VKeyState = U 
		break

	Click right
	Sleep, 5000
	Send, 8
	Sleep, 3000
	Click right
	Sleep, 4 * Minutes
} 
return

Link to comment
Share on other sites

I use the arrow keys instead of WASD, but here's my script. It uses [ for walk, ] for run, \ to stop, and L to search and loot.

 

I haven't tried o and p yet so I'm not sure if they work. :p

 

; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
;
; Script Function:
;	7 Days to Die auto run
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force ; Only one instance at a time
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

running := 0

|::
\::
; stop movement
ControlSend, , {LShift up}{Up up}, 7 Days To Die
; stop mouseclick
send {click U}
send {click U right}
return

#IfWinActive, 7 Days To Die
[::
{::
; walk
ControlSend, , {LShift up}{Up down}, 7 Days To Die
return

]::
; run
ControlSend, , {LShift down}{Up down}, 7 Days To Die
return

l::
; search and take all
ControlSend, , e, 7 Days To Die
sleep 1100
ControlSend, , r, 7 Days To Die
return

o::
;left mouseclick
send {click D}
return

p::
;left mouseclick
send {click D right}
return

Link to comment
Share on other sites

  • 4 weeks later...

All right, maybe some Smart Person would like to help me out. Can anyone write a script to change the shift key behavior as follows: As long as the W key is held down pressing the shift key results in it remaining in a down state until it is pressed again or the W key is released. Basically Borderlands style sprinting to take some strain off the old pinkie finger.

Link to comment
Share on other sites

This kind of does what you want?

Enable autorun until W is tapped or switch to autowalk if Shift is tapped.

 

(with latest tweaks)

 

The Drop Item feature may require new click coordinates based on your screen resolution.

 

The AFK guard saved me at least one death by starvation. (which always costs 100+ wellness =)

 

GroupAdd, Diediedie ,7 Days To Die,,,Firefox
#IfWinActive,7 Days To Die


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Shift + Mouse button 5 locks down LMB for larger mining projects.
;Simply press LMB to stop.
+XButton2::
Send {e up}{e down}
Click up left
sleep ,10
Click down left
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Shift + Mouse button 4 is autofire for the E key when I traipse around the desert, picking up stuff.
;E to stop.
+XButton1::
Loop 
{ 
	GetKeyState, VKeyState, RButton, P 
	if VKeyState = D 
	{ 
		Send, e
		GetKeyState, VKeyState, Shift
		if VKeyState = D
		{
			TempWalk := 1
			Send {shift up}
		}
	} else {
		if TempWalk
		{
			TempWalk := 0
			Send {shift down}
		}
	}

	Sleep, 50
	GetKeyState, VKeyState, e, P 
	if VKeyState = D 
		break 
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Ctrl + B,  autofire for RMB,  used for large scale planting
;RMB to stop.
^b::
Loop 
{ 
	Click right
	Sleep, 150
	GetKeyState, VKeyState, RButton, P 
	if VKeyState = D 
		break 
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Connection script, if the server is full or decides to play games with me
^PgUp::
Loop 
{ 
	GetKeyState, VKeyState, PgUp, P 
	if VKeyState = U
		break 

		MouseClick, left,  816,  474
		Sleep, 1200
		MouseClick, left,  1278,  995
		Sleep, 1200
		MouseClick, left,  705,  578
MouseMove,  940,  482
		Sleep, 2000
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Toggle Autorun
; Press SHIFT afterwards to lower the speed to autowalk. MButton will then switch back to autorun.
*MButton::

	GetKeyState, VKeyState, w
	if VKeyState = U
	{
		Send {w down}{shift down}
	} else {
			Send {w up}{shift up}
	}
return



;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;CTRL-g,  AFK guard
^g::
SoundBeep, 800
Minutes := 60000
Loop
{ 
	Sleep, 10 * Minutes
	SoundBeep, 800

	;Check if there has been no physical user input for...
	if (A_TimeIdlePhysical > 55 * Minutes)
		{ 
		Send {Alt down}{F4}{Alt up}
		exit
		} 
} 
return



;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Removing unwanted items from inventory or opened containers is a lot of work in this game. So...
;Q: drop item from INVENTORY / CONTAINER
; drop position left of inventory:   MouseClick, left,  410,  572

q::
if ChatActive
{ 
	Send, q
} 
else
{ 
	MouseGetPos, StartX, StartY
	MouseClick, left,  StartX,  StartY
	Send, q
	Sleep, 150
	MouseMove, 410, 572,0
	MouseClick, left,  410,  572
	Sleep, 5
	MouseClick, left,  410,  572
	MouseMove, StartX, StartY,0
} 
return


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Suspend "q" while in the text chat, starting with "t" and ending with ESC/ENTER

ESC::
ChatActive := 0
Send, {ESC}
return

ENTER::
ChatActive := 0
Send, {ENTER}
return

t::
ChatActive := 1
Send, t
return

Link to comment
Share on other sites

  • 4 weeks later...

Updated the AFK guard.

After I starved to death AGAIN.

 

Now it shuts down the game after about 1 hour of inactivity even if the game is alt-tabbed and minimised...

(which is what got me last time - and going from 200 to 30 wellness is so annoying)

 

 

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;CTRL-g,  AFK guard
^g::
SoundBeep, 800
Minutes := 60000

Loop
{ 
	Sleep, 10 * Minutes
	SoundBeep, 800

	IfWinExist ,7 Days To Die
	{ 
		;Check if there has been no physical user input for...
		if (A_TimeIdlePhysical > 55 * Minutes)
		    WinKill ,7 Days To Die
	} 
	else
	{ 
		break
	} 
} 
return

 

Overkill?

I think not.

Link to comment
Share on other sites

My original is at http://pastebin.com/i37tTybJ and I've tried copy/pasting the following parts of yours -

 

Shift + Mouse button 4 (changing it to the p key)

Shift + Mouse button 5 (changing it to the o key)

 

I've also tried adapting Shift + Mouse button 4 to make an auto-plant using the i key.

 

I've remapped the following in 7DTD itself -

Arrow keys instead of WASD

Run - LShift

Primary - LControl

Secondary - LAlt

 

My global "stop" key is \

 

In short, the original script works, but the additions don't work. It's probably a combination of my remapped keys, changing the input keys, and maybe making \ stop it.

 

Do you think you could add the your Shift + Mouse button 4, Shift + Mouse button 5, and the auto-plant to my original? After trying for a few hours I give up. lol

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...
Hey, is this made using AutoIT?

 

If you were asking about mine, it was made using Notepad++ and eventually worked after tweaking it.

 

I tried asking Gazz for help, but I guess he was "too busy".

 

I think he meant was the software, AutoHotkey, written using the AutoIT scripting/programming language.

I don't know the answer... but it sounds like a job for AutoIT :)

The same question popped into my mind as I was reading this thread.

Link to comment
Share on other sites

  • 7 months later...

Here's a dumbed down script that works for alpha 13.3

 

Features:

Autorun (press middle mouse button down once, and once more to stop)

Autohit (Shift + Mouse button 5)

 

Thanks again to Gazz for this tutorial.

 

#IfWinActive,7 Days To Die
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Shift + Mouse button 5 locks down LMB for larger mining projects.
;Simply press LMB to stop.
+XButton2::
Send {e up}{e down}
Click up left
sleep ,10
Click down left
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Connection script, if the server is full or decides to play games with me
PgUp::
Loop 
{ 
	GetKeyState, VKeyState, PgUp, P 
	if VKeyState = U
		break 

		MouseClick, left,  785,  400
		Sleep, 1200
		MouseClick, left,  1200,  833
		Sleep, 1200
	MouseClick, left,  1001,  479
		Sleep, 2000
} 
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;Toggle Autorun
; Press SHIFT afterwards to lower the speed to autowalk. MButton will then switch back to autorun.
*MButton::
	GetKeyState, VKeyState, Shift
	if VKeyState = D
	{
		Send {w up}{shift up}
	} else {
		Send {w down}{shift down}
	}
		return
return

Link to comment
Share on other sites

  • 2 weeks later...

Does anyone else have that problem?

 

Since A12 I can no longer use SPACE on the console when writing global messages to the server.

 

I.used.to.talk.like.this which is... ugh.

 

 

Eventually I wrote a keyboard script to auto-replace the spaces with a character that the game would print as a space.

 

#IfWinActive,37.220.12.250 - KiTTY

*ESC::
ChatActive := 0
Send, {ESC}
return

*ENTER::
ChatActive := 0
Send, {ENTER}
return

:*:say::
send, say{space}
ChatActive := 1
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

*SPACE::
if ChatActive
{ 
	Send,{ASC 127}
} 
else
{ 
	send {space}
} 
return

 

It only triggers for the "say" command and goes dormant on an ENTER or ESC.

Link to comment
Share on other sites

  • 2 months later...

this is great!

 

is there a way to make a key press like (Send q) and punch work even when 7dTD window does not have focus?

 

my scenario (crafting and raising athletics)...

1. Press Q every 50ms to drop item in slot 4 (stone axe)

2. Punch a wall between dropping

3. option eat

4. do this while I am reading email :)

 

so far I have:

 

; #IfWinActive,7 Days To Die

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SetTimer eF, 50

NumpadMult:: Toggle := !Toggle

eF:
   If (!Toggle)
       Return

   Send, q
return

NumpadSub::Send % "{Click " . ( GetKeyState("LButton") ? "Up}" : "Down}" )

Link to comment
Share on other sites

  • 3 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...