Skip to content

AutoHotKey

매크로의 세계

[오토핫키] 이미지서치 기본

by CroitzK posted Mar 11, 2020 Views 79 Likes 0 Replies 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

#샘플 코드


ImageSearch, vx, vy, 0, 0, A_ScreenWidth, A_ScreenHeight, *trans00FF00 *20 ex.png

If ErrorLevel = 0
    msgBox, 이미지를 찾음
else If ErrorLevel = 1
    msgBox, 이미지를 못찾음
else If ErrorLevel = 2
    msgBox, 에러 발생


vx, vy는 찾은 이미지의 좌표값 대입


0, 0 은 검색할 좌표 시작점

A_ScreenWidth, A_ScreenHeight는 검색할 좌표의 끝점

   → 모니터 좌측상단 끝부분 부터 모니터 우측하단 끝부분까지 (해상도에 따라 정해짐)


*trans00FF00 은 RGB 색상코드 00FF00를 투명처리 (검색에서 제외)


*20 은 정확도 (0에 가까울수록 100%에 근접)


ex.png 는 검색할 이미지 파일명 및 확장자 (*.png 또는 *.bmp)


중요: bmp 파일로 저장할 땐 24비트 bmp파일로 저장할 것


<끝>

?

[오토핫키] 포인터 메모리 읽어와서 게임 자동화 구현 테스트

by CroitzK posted Mar 08, 2020 Views 131 Likes 0 Replies 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부



as.png




#샘플 코드


#Include <classMemory>

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
; You can use this code to check if you have installed the class correctly.
if (_ClassMemory.__Class != "_ClassMemory")
{
    msgbox class memory not correctly installed. Or the (global class) variable "_ClassMemory" has been overwritten
    ExitApp
}
Gui, font,, arial
Gui, Add, GroupBox, x10 y10 w210 h120, 현황판
Gui, Add, Button, x10 y160 w105 h30 vSTART, START
Gui, Add, Button, x115 y160 w105 h30 vPAUSE, PAUSE
Gui, add, Text, x20 y30 vClassName w140, N/A
Gui, Add, Text, x20 y50 vBP w140 cBF8F00, BP: N/A
Gui, Add, Text, x20 y65 vHP w100 cRed, HP: N/A
Gui, Add, Progress, x20 y80 w80 h10 cRed BackgroundWhite Range0-100 vHBar
Gui, Add, Text, x110 y65 vMP w100 cBlue, MP: N/A
Gui, Add, Progress, x110 y80 w80 h10 cBlue BackgroundWhite Range0-100 vMBar
Gui, Add, Text, x43 y95 vHPotion w140, HP포션: N/A
Gui, Add, Text, x43 y110 vMPotion w140, MP포션: N/A
Gui, Add, Checkbox, x20 y95 w23 vUseItemHP
Gui, Add, Checkbox, x20 y110 w23 vUseItemMP
Gui, Add, Text, x10 y135 vMoney w100, 소지금: N/A
GuiControl,, START, START(F1)
GuiControl,, PAUSE, PAUSE(F2)
GuiControl, Enable, START
GuiControl, Disable, PAUSE
Gui, Show, w230 h200, Octopath Traveler Support
Gui, -MinimizeBox -MaximizeBox
return

GuiClose:
	ExitApp

F1::
ButtonSTART:
	GuiControl, Disable, START
	GuiControl, Enable, PAUSE
	PlayAndStop := 1
	goto, PLAY

F2::
ButtonPAUSE:
	GuiControl, Enable, START
	GuiControl, Disable, PAUSE
	PlayAndStop := 0
	WinActivate, Octopath Traveler Support
	goto, STOP

isMyTurn(ByRef character, ByRef characterName, ByRef myTurn, ByRef bpText, bp)
{
	character := 0
	characterName := "Enermy"
	myTurn := 0
	bpText := "○○○○○"
	ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 opilea.bmp
	if(ErrorLevel =  0)
	{
		character := 1
		characterName := "오필리아"
		myTurn := 1
	}
	ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 hanit.bmp
	if(ErrorLevel =  0)
	{
		character := 2
		characterName := "하닛"
		myTurn := 1
	}
	ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 terion.bmp
	if(ErrorLevel =  0)
	{
		character := 3
		characterName := "테리온"
		myTurn := 1
	}
	if bp = 1
		bpText := "●○○○○"
	if bp = 2
		bpText := "●●○○○"
	if bp = 3
		bpText := "●●●○○"
	if bp = 4
		bpText := "●●●●○"
	if bp = 5
		bpText := "●●●●●"
	return
}

isMyMenu(ByRef i)
{
	ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *50 isMyTurn.png
	if(ErrorLevel = 0)
	{
		i := 1
	}
	ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 isMagic1.png
	if(ErrorLevel = 0)
	{
		i := 31
	}
	return i
}

zKeySend(cnt)
{
	loopCount := 1
	if (cnt > 0)
	{
		loopCount := cnt
	}
	
	loop, %loopCount%
	{
		ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
		sleep, 50
	}
	return
}

sKeySend(cnt)
{
	loopCount := 1
	if (cnt > 0)
	{
		loopCount := cnt
	}
	
	loop, %loopCount%
	{
		ControlSend,,{s}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
		sleep, 50
	}
	return
}

downKeySend(cnt)
{
	loopCount := 1
	if (cnt > 0)
	{
		loopCount := cnt
	}
	
	loop, %loopCount%
	{
		ControlSend,,{down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
		sleep, 50
	}
	return
}

PLAY:
if(PlayAndStop = 1)
{
	character := 0
	myTurn := 0
	myMenu := 0
	loop
	{
		if(PlayAndStop = 0)
		{
			break
		}
		ifWinExist, ahk_exe Octopath_Traveler-Win64-Shipping.exe
		{
			WinActivate, ahk_exe Octopath_Traveler-Win64-Shipping.exe
		}
		mem := new _ClassMemory("ahk_exe Octopath_Traveler-Win64-Shipping.exe", "", hProcessCopy) ; *****
		if !isObject(mem) 
		{
			msgbox failed to open a handle
			if (hProcessCopy = 0)
				msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter. 
			else if (hProcessCopy = "")
				msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as 	admin. Consult A_LastError for more information.
				ExitApp
		}
		value := mem.read(mem.BaseAddress + 0x0289F030, "UInt", 0x78, 0x88, 0x78, 0x380, 0x3D8, 0x78, 0x428)
		hPotion := mem.read(mem.BaseAddress + 0x0289F070, "UInt", 0x78, 0x20, 0xA0, 0x88, 0x78, 0x3A8, 0x4)
		mPotion := mem.read(mem.BaseAddress + 0x0289F070, "UInt", 0x78, 0x20, 0xA0, 0x88, 0x78, 0x3A8, 0x14)
		money := mem.read(mem.BaseAddress + 0x0289F070, "UInt", 0x78, 0x20, 0xA0, 0x88, 0x78, 0x370, 0x158)
		GuiControl,, HPotion, HP포션:%hPotion%개
		GuiControl,, MPotion, MP포션:%mPotion%개
		GuiControl,, Money, 소지금:%money%
		if (value != null)
		{
			ControlSend,,{Left up}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
			ControlSend,,{Right up}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
			ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *20 next.png
			if(ErrorLevel = 0){
				ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
				sleep, 50
			}
			else
			{
				isMyTurn(character, characterName, myTurn, bpText, value)
				sleep, 250
				GuiControl,, ClassName, %characterName%(%character%)
				minHp := mem.read(mem.BaseAddress + 0x0289F030, "UInt", 0x78, 0x88, 0x78, 0x380, 0x3D8, 0x78, 0x3E4)
				maxHp := mem.read(mem.BaseAddress + 0x0289F030, "UInt", 0x78, 0x88, 0x78, 0x380, 0x3D8, 0x78, 0x3EC)
				minMp := mem.read(mem.BaseAddress + 0x0289F030, "UInt", 0x78, 0x88, 0x78, 0x380, 0x3D8, 0x78, 0x3E8)
				maxMp := mem.read(mem.BaseAddress + 0x0289F030, "UInt", 0x78, 0x88, 0x78, 0x380, 0x3D8, 0x78, 0x3F0)
				sleep, 250
				GuiControl,, BP, BP:%value% %bpText%
				GuiControl,, HP, HP:%minHp%/%maxHp%
				GuiControl,, MP, MP:%minMp%/%maxMp%
				Gui, submit, nohide
				if(character != 0 && myTurn = 1)
				{
					hpRate := (minHp * 100) / maxHp
					mpRate := (minMp * 100) / maxMp
					GuiControl,, HBar, %hpRate%
					GuiControl,, MBar, %mpRate%
					isMyMenu(myMenu)
					if(hpRate > 50 && myTurn = 1 && myMenu = 1)
					{
						if(value > 2)
						{
							sKeySend(3)
							sleep, 250
						}
						zKeySend(2)
						myTurn := 0
						sleep, 1000
					}
					else if(hpRate <= 50 && minMp > 8 && character = 1 && myTurn = 1)
					{
						isMyMenu(myMenu)
						if(myMenu = 31)
						{
							zKeySend(3)
							myTurn := 0
						}
						else
						{
							downKeySend(1)
						}
					}
					else if(hpRate <= 50 && character > 1 && hPotion > 0 && UseItemHP = 1 && myTurn = 1)
					{
						ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 isUseItem.png
						if(ErrorLevel = 1)
						{
							ControlSend,,{Down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
							sleep, 50
						}
						else if (ErrorLevel = 0)
						{
							ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
							sleep, 50
						}
						ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 isHPItem.png
						if(ErrorLevel = 0)
						{
							loop, 2
							{
								ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
								sleep, 50
							}
							myTurn := 0
						}
					}
					else if(hpRate <= 50 && character = 1 && minMp < 8 && hPotion > 0 && UseItemHP = 1 && myTurn = 1)
					{
						ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 isUseItem.png
						if(ErrorLevel = 1)
						{
							ControlSend,,{Down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
							sleep, 50
						}
						else if (ErrorLevel = 0)
						{
							ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
							sleep, 50
						}
						ImageSearch, vx, vy, 1, 1, A_ScreenWidth, A_ScreenHeight, *30 isHPItem.png
						if(ErrorLevel = 0)
						{
							loop, 2
							{
								ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
								sleep, 50
							}
							myTurn := 0
						}
					}
					else if(minMp < 8 && mPotion > 0 && UseItemMP = 1 && myTurn = 1)
					{
						loop, 3
						{
							ControlSend,,{Down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
							sleep, 50
						}
						ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
						sleep, 50
						ControlSend,,{Down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
						sleep, 50
						ControlSend,,{z}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
						myTurn := 0
					}
				}
				myMenu := null
				myTurn := null
				character := null
				characterName := null
				hpRate := null
				mpRate := null
			}
		}
		else
		{
			GuiControl,, ClassName, N/A
			GuiControl,, BP, 전투중이 아닙니다.
			GuiControl,, HP, HP:N/A
			GuiControl,, MP, MP:N/A
			GuiControl,, HBar, 0
			GuiControl,, MBar, 0
			ControlSend,,{Left down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
			sleep, 1000
			ControlSend,,{Left up}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
			sleep, 100
			ControlSend,,{Right down}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
			sleep, 1000
			ControlSend,,{Right up}, ahk_exe Octopath_Traveler-Win64-Shipping.exe
		}
	}
	return
}

STOP:
	return


classMemory가 설치되어 있어야 작동 한다.


참조: http://www.agmserver.com/main/blog_ahk/570

?

[오토핫키] 비활성 마우스클릭

by CroitzK posted Mar 08, 2020 Views 87 Likes 0 Replies 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

#샘플 코드


Random, ClickX, 130, 400 ; 랜덤좌표
Random, ClickY, 280, 580 ; 랜덤좌표
Random, sleepTime, 1, 355 ; 랜덤 슬립타임
Iparam:=ClickX|ClickY<<16 ; 마우스좌표 코드 (16진수)
PostMessage, 0x201,1, %Iparam%, RenderWindow1, ahk_pid 9420 ;클릭
PostMessage, 0x202,0, %Iparam%, RenderWindow1, ahk_pid 9420 ;때기
Sleep, sleepTime

편리하다.

?

[오토핫키] 메모리 및 포인터 오프셋 읽어오기

by CroitzK posted Mar 08, 2020 Views 122 Likes 0 Replies 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부


#샘플 코드

; The contents of this file can be copied directly into your script. Alternately, you can copy the classMemory.ahk file into your library folder,
; in which case you will need to use the #include directive in your script i.e. 
  
#Include <classMemory>
 
; You can use this code to check if you have installed the class correctly.
 
if (_ClassMemory.__Class != "_ClassMemory")
{
    msgbox class memory not correctly installed. Or the (global class) variable "_ClassMemory" has been overwritten
    ExitApp
}
 
f1::
; Open a process with sufficient access to read and write memory addresses (this is required before you can use the other functions)
; You only need to do this once. But if the process closes/restarts, then you will need to perform this step again.
; .isHandleValid() can be used to check if program has restarted.
; Note: The program identifier can be any AHK windowTitle i.e.ahk_exe, ahk_class, ahk_pid, or simply the window title. 
; Unlike AHK this defaults to an exact match, but this can be changed via the passed parameter.
; hProcessCopy is an optional variable in which the opened handled is stored. 
; *****  change FTLGAME.exe to your process name ******
mem := new _ClassMemory("ahk_exe FTLGAME.exe", "", hProcessCopy) ; *****
 
; Check if the above method was successful.
if !isObject(mem) 
{
    msgbox failed to open a handle
    if (hProcessCopy = 0)
        msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter. 
    else if (hProcessCopy = "")
        msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. Consult A_LastError for more information.
    ExitApp
}
 
; read a pointer - mem.BaseAddress is automatically set to the base address.
value := mem.read(mem.BaseAddress + 0x00B8C83C, "UInt", 0x0, 0xA8, 0x3FC)
 
msgbox val = %value%
 
return


  • PS. classMemory.ahk 파일은 내문서\[사용자명]\doucuments\autohotkey\lib 폴더? 에 첨부
  • PS2. 실행중 오류발생시 관리자권한으로 실행


# 본문 코드 출처: https://www.autohotkey.com/boards/viewtopic.php?t=44241

# 다운로드 링크: classMemory-master.zip - 자료 출처: https://github.com/Kalamity/classMemory

?

[오토핫키] AutoHotKey 및 SciTe4 설치

by CroitzK posted Mar 08, 2020 Views 72 Likes 0 Replies 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

목록
Board Pagination Prev 1 Next
/ 1

Calender

2020.07
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Time Info

Counter Info

방문자수

전체 : 44,995
오늘 : 9
어제 : 34

페이지뷰

전체 : 1,615,727
오늘 : 205
어제 : 1,686

COPYRIGHT 2009 by AGMServer.com

Powered by Xpress Engine / Designed by Sketchbook

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소