Skip to content

Instantly share code, notes, and snippets.

@danielpza
Last active December 27, 2022 22:45
Show Gist options
  • Save danielpza/4f2243cb3d66cb27f3769ab123a082f3 to your computer and use it in GitHub Desktop.
Save danielpza/4f2243cb3d66cb27f3769ab123a082f3 to your computer and use it in GitHub Desktop.
Valheim AHK (requires ahk v2)
#HotIf WinActive("ahk_exe valheim.exe")
sleeptime := 30
SetMouseDelay sleeptime
SetKeyDelay -1, sleeptime
SetDefaultMouseSpeed sleeptime
Wait() {
Sleep(sleeptime)
}
selectedcolor := "0xDAA66A"
F9::Reload()
F12::Suspend()
x::Send("6")
c::Send("7")
v::Send("8")
n::{
;; deposit all
static sx := 60
static sy := 200
static xx := 8
static yy := 2
static d := 70
x := 0
while (x < xx) {
y := 0
while (y < yy) {
Send("^{click " sx + d * x " " sy + d * y "}")
Wait()
y++
}
x++
}
}
p up::{
MouseGetPos(&mousex, &mousey)
color := PixelGetColor(mousex, mousey)
A_Clipboard := Format('{1}, {2}, "{3}"', mousex, mousey, color)
}
e::{
if (CheckPixel(428, 431, "0xFFA13D")) {
; if split stack menu is open
MouseGetPos(&x, &y)
Click(421, 428)
Wait()
MouseMove(x, y)
return
} else {
Send("h")
}
}
*f::{
while (GetKeyState("f", "p")) {
if (!CheckPixel(997, 641, "0xDBDB00")) {
Sleep(30)
continue
}
Send("h")
Wait()
}
KeyWait("f")
}
; ^LButton::{
; while (GetKeyState("lbutton", "p")) {
; Click()
; Wait()
; }
; KeyWait("lbutton")
; }
; n::{
; if (!BuildMenuIsOpen()) {
; OpenBuildMenu()
; }
; Click(881, 361)
; Sleep(20)
; Click(685, 409)
; }
z up::{
static isrunning := false
isrunning := !isrunning
if (isrunning) {
Send("{w down}")
} else {
Send("{w up}")
}
}
SelectHammer() {
if (!HammerIsSelected()) {
ToggleHammer()
}
}
OpenBuildMenu() {
SelectHammer()
Press("rbutton")
}
ExitBuildMenu() {
Press("rbutton")
}
ToggleHammer() {
Press("8")
}
HammerIsSelected() {
return CheckPixel(587, 89, "0x5C99CE")
}
BuildMenuIsOpen() {
return CheckPixel(1358, 354, "0xFFFFFF")
}
Press(key) {
static lastkey := ""
if (lastkey == key){
sleep 30
}
lastkey := key
Send("{" key " down}")
sleep 30
Send("{" key " up}")
}
ColorDiff(color1, color2){
; https://www.autohotkey.com/boards/viewtopic.php?t=65491
tr := format("{:d}","0x" . substr(color1,3,2))
tg := format("{:d}","0x" . substr(color1,5,2))
tb := format("{:d}","0x" . substr(color1,7,2))
; split pixel into rgb
pr := format("{:d}","0x" . substr(color2,3,2))
pg := format("{:d}","0x" . substr(color2,5,2))
pb := format("{:d}","0x" . substr(color2,7,2))
return Abs(tr - pr) + Abs(tg - pg) + Abs(tb - pb)
}
CheckPixel(x, y, ccolor) {
return ColorDiff(PixelGetColor(x, y), ccolor) < 100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment