johnbl - I don't think you understood what I was asking.
_x1 := 800 ; top left pixel
_y1 := 600 ; top left pixel
_x2 := 640 ; width
_y2 := 480 ; height
would not work the x2 and y2 values "have" to be greater than the x1 and y1 values.
_x1 := 800 ; top left pixel
_y1 := 600 ; top left pixel
_x2 := 1400; bottom right pixel
_y2 := 1080; bottom right pixel
would be proper values.
my issue with the _x _y _w _h is that you need to "manualy" subtract coordinates to get the proper _w and _h values (I think the program should be doing this for you... it should be making your life easier not harder...)
example on 1440p if I find the coordinates for the skill bar button 4 they are - 1116, 1345 and 1173, 1402
- well, there I already found 4 values I should just be able to input those... and be done with it...
- however, using _x _y _w _h would not allow me to just enter these 4 values because I would first have to minu the fist values from the second values (to find the width and height)
- then end up getting 1116, 1345 and 57, 57
- its a matter of semantics for me...
Anyways, this is what I ended up using below and seems to be working well for me now.
Example Script
Code:
; example script
SendMode Input
SetMouseDelay -1
SetBatchLines -1
Process, Priority,, High
SysGet, screenSizeX, 0
SysGet, screenSizeY, 1
#IfWinActive ahk_class D3 Main Window Class
#include Gdip_All.ahk
#include Gdip_ImageSearch.ahk
#include diabloFunctions.ahk
; sets defualt pics dir
default_pictures := "pictures/1440p/"
if (screenSizeX != 2560 || screenSizeY != 1440)
default_pictures := "pictures/1080p/"
; chat on icon 1
x1 := 31, y1 := 1172, x2 := 51, y2 := 1189
if (screenSizeX != 2560 || screenSizeY != 1440)
x1 *= (screenSizeX / 2560), y1 *= (screenSizeY / 1440), x2 *= (screenSizeX / 2560), y2 *= (screenSizeY / 1440)
chat_on_icon1 := x1 "|" y1 "|" x2 "|" y2
; skill bar #4
x1 := 1116, y1 := 1345, x2 := 1173, y2 := 1402
if (screenSizeX != 2560 || screenSizeY != 1440)
x1 *= (screenSizeX / 2560), y1 *= (screenSizeY / 1440), x2 *= (screenSizeX / 2560), y2 *= (screenSizeY / 1440)
skill_bar_4 := x1 "|" y1 "|" x2 "|" y2
; checks if chat window is open
~Enter::
sleep 75
if checkImage(default_pictures "chat_on1_1.png", chat_on_icon1) or checkImage(default_pictures "chat_on1_2.png", chat_on_icon1)
{
tooltip, chat is on, 0,0
chat_isOn := True
}
else
{
tooltip, chat is off, 0,0
chat_isOn := False
}
Return
; take picture of chat_on icon (you will need to rename and move file after) press enter before taking pic
7::
screenShot(chat_on_icon1)
Return
; take picture of archon skill on skill slot #4 (you will need to rename and move file after)
6::
screenShot(skill_bar_4)
Return
; after pressing five it will wait till archon off cdr to press 4 button
5::
findImage(default_pictures "archon.png", skill_bar_4)
sleep 250
SendInput, 4
Return
Below is the file called diabloFunctions.ahk
Code:
; ============================================================================================
; search for image in diablo - keep looping until img found
; ============================================================================================
findImage(pictureName, Screen)
{
S := StrSplit(Screen, "|")
x1 := S[1], y1 := S[2], x2 := S[3], y2 := S[4]
gdipToken := Gdip_Startup()
hwnd := WinExist("ahk_exe Diablo III64.exe")
image_to_find := Gdip_CreateBitmapFromFile(pictureName)
if (image_to_find <= 0)
msgbox, can not find %pictureName%
while (!true_or_false_var)
{
screen_snapshot := Gdip_BitmapFromHWNDCropped(hwnd, x1 "|" y1 "|" x2 "|" y2)
true_or_false_var := Gdip_ImageSearch(screen_snapshot, image_to_find, LIST,0,0,0,0,5,0xFFFFFF,1,0)
}
Gdip_DisposeImage(image_to_find)
Gdip_DisposeImage(screen_snapshot)
Gdip_Shutdown(gdipToken)
Return
}
; ============================================================================================
; check for image in diablo - just check if img is there once
; ============================================================================================
checkImage(pictureName, Screen)
{
S := StrSplit(Screen, "|")
x1 := S[1], y1 := S[2], x2 := S[3], y2 := S[4]
gdipToken := Gdip_Startup()
hwnd := WinExist("ahk_exe Diablo III64.exe")
image_to_find := Gdip_CreateBitmapFromFile(pictureName)
if (image_to_find <= 0)
msgbox, can not find %pictureName%
screen_snapshot := Gdip_BitmapFromHWNDCropped(hwnd, x1 "|" y1 "|" x2 "|" y2)
true_or_false_var := Gdip_ImageSearch(screen_snapshot, image_to_find, LIST,0,0,0,0,5,0xFFFFFF,1,0)
Gdip_DisposeImage(image_to_find)
Gdip_DisposeImage(screen_snapshot)
Gdip_Shutdown(gdipToken)
Return true_or_false_var
}
; ============================================================================================
; take screen shot
; ============================================================================================
screenShot(Screen)
{
S := StrSplit(Screen, "|")
x1 := S[1], y1 := S[2], x2 := S[3], y2 := S[4]
pToken := Gdip_Startup()
hwnd := WinExist("ahk_exe Diablo III64.exe")
pBitmap := Gdip_BitmapFromHWNDCropped(hwnd, x1 "|" y1 "|" x2 "|" y2)
Gdip_SaveBitmapToFile(pBitmap, A_Now ".png", 100)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Return
}
; ============================================================================================
; used for getting a cropped image from screen (from thud fourms)
; ============================================================================================
Gdip_BitmapFromHWNDCropped(hwnd, Screen)
{
Raster := ""
Ptr := A_PtrSize ? "UPtr" : "UInt"
hhdc := GetDCEx(hwnd, 3)
S := StrSplit(Screen, "|")
x1 := S[1], y1 := S[2], x2 := S[3] - S[1], y2 := S[4] - S[2]
chdc := CreateCompatibleDC(), hbm := CreateDIBSection(x2, y2, chdc)
obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
BitBlt(chdc, 0, 0, x2, y2, hhdc, x1, y1, Raster)
ReleaseDC(hhdc)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
return pBitmap
}
wigworth
- yes these method work as of nov 16 2019 with current thud