generate a circle overlay for specific application

Ask gaming related questions (AHK v1.1 and older)
Gaffgarion
Posts: 9
Joined: 04 Oct 2017, 06:09

generate a circle overlay for specific application

19 Nov 2018, 02:14

so this game called rotmg, its a flash based game.

and basically what i need is like some sort of overlay/marker on the screen (always on top) on the specific coordinate of the flash player.

because this game is best played windowed, so i cant help but to move it around a lot if i were watching videos or doing something else, so i need the circle overlay/marker to retain its position even if i move the flash player around.

and i need it toggled to right mouse button, so first click will show the overlay and if i click it again it will disappear.

below is the closest example of what i meant, im using paint just to draw the circle.

example without overlay
Spoiler

example with overlay
Spoiler

any help is much appreciated!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: generate a circle overlay for specific application

19 Nov 2018, 11:14

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1
SetTitleMatchMode 2

GAME_TITLE := "ahk_exe notepad.exe"
X_OFFSET := 50
Y_OFFSET := 50

hCircle := makeCircle(0x00FF00, 200, 2, 140)
SetTimer MoveCircle, 100
Return

MoveCircle:
	if (hGame := WinActive(GAME_TITLE))
	{
		WinGetPos x, y, , , % "ahk_id " hGame
		Gui %hCircle%: Show, % Format("NoActivate x{} y{}", x + X_OFFSET, y + Y_OFFSET)
	}
	else
		Gui %hCircle%: Hide
Return

makeCircle(color, r := 400, thickness := 10, transparency := 254) {
	static HWND := MakeGui()

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", r, "Int", r)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", r - thickness, "Int", r - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%r% h%r% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}
for cleverer ways of keeping the circle in sync with the window, look into implementing a shell- or wineventhook
Gaffgarion
Posts: 9
Joined: 04 Oct 2017, 06:09

Re: generate a circle overlay for specific application

19 Nov 2018, 19:31

swagfag wrote:
19 Nov 2018, 11:14

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1
SetTitleMatchMode 2

GAME_TITLE := "ahk_exe notepad.exe"
X_OFFSET := 50
Y_OFFSET := 50

hCircle := makeCircle(0x00FF00, 200, 2, 140)
SetTimer MoveCircle, 100
Return

MoveCircle:
	if (hGame := WinActive(GAME_TITLE))
	{
		WinGetPos x, y, , , % "ahk_id " hGame
		Gui %hCircle%: Show, % Format("NoActivate x{} y{}", x + X_OFFSET, y + Y_OFFSET)
	}
	else
		Gui %hCircle%: Hide
Return

makeCircle(color, r := 400, thickness := 10, transparency := 254) {
	static HWND := MakeGui()

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", r, "Int", r)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", r - thickness, "Int", r - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%r% h%r% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}
for cleverer ways of keeping the circle in sync with the window, look into implementing a shell- or wineventhook
hi, thank you very much for your help!

it works great, but theres something i dont know how to determine, its about the coordinate and the how to change the size of the circle
first off, the coordinate, you set in x50 and y50, but when i check with autohotkey's window spy, in the "relative" it said x150 and y150, so how do you set the coordinate so its appear at the precise coordinate that i want?

and then the diameter of the circle
this code > hCircle := makeCircle(0x00FF00, 200, 2, 140)
i tried to change it to this
hCircle := makeCircle(0x00FF00, 300, 2, 140)
it does make the circle bigger, but all of the sudden the circle moved to the right a bit, like the coordinate is still the same in script but the circle moved away because i made it bigger

can you help me on this?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: generate a circle overlay for specific application

20 Nov 2018, 10:54

just calculate the position and move it by that amount
here it is with the origin shifted to the center, instead of the top-left corner:

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1
SetTitleMatchMode 2

GAME_TITLE := "ahk_exe notepad.exe"
X_OFFSET := 0
Y_OFFSET := 0

hCircle := makeCircle(0x00FF00, r := 200, 2, 140)
SetTimer MoveCircle, 100
Return

MoveCircle:
	if (hGame := WinActive(GAME_TITLE))
	{
		WinGetPos x, y, , , % "ahk_id " hGame
		Gui %hCircle%: Show, % Format("NoActivate x{} y{}", x + X_OFFSET - r, y + Y_OFFSET - r)
	}
	else
		Gui %hCircle%: Hide
Return

makeCircle(color, r := 400, thickness := 10, transparency := 254) {
	static HWND := MakeGui()
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}
Gaffgarion
Posts: 9
Joined: 04 Oct 2017, 06:09

Re: generate a circle overlay for specific application

20 Nov 2018, 19:27

swagfag wrote:
20 Nov 2018, 10:54
just calculate the position and move it by that amount
here it is with the origin shifted to the center, instead of the top-left corner:

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1
SetTitleMatchMode 2

GAME_TITLE := "ahk_exe notepad.exe"
X_OFFSET := 0
Y_OFFSET := 0

hCircle := makeCircle(0x00FF00, r := 200, 2, 140)
SetTimer MoveCircle, 100
Return

MoveCircle:
	if (hGame := WinActive(GAME_TITLE))
	{
		WinGetPos x, y, , , % "ahk_id " hGame
		Gui %hCircle%: Show, % Format("NoActivate x{} y{}", x + X_OFFSET - r, y + Y_OFFSET - r)
	}
	else
		Gui %hCircle%: Hide
Return

makeCircle(color, r := 400, thickness := 10, transparency := 254) {
	static HWND := MakeGui()
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}
thanks, i got it working

now, is it possible to make the gui toggleable?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: generate a circle overlay for specific application

20 Nov 2018, 21:54

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1
SetTitleMatchMode 2

GAME_TITLE := "ahk_exe notepad.exe"
X_OFFSET := 0
Y_OFFSET := 0

hCircle := makeCircle(0x00FF00, r := 200, 2, 140)
SetTimer MoveCircle, 100
Return

*RButton::isCircleVisible := !isCircleVisible

MoveCircle:
	if ((hGame := WinActive(GAME_TITLE)) && isCircleVisible)
	{
		WinGetPos x, y, , , % "ahk_id " hGame
		Gui %hCircle%: Show, % Format("NoActivate x{} y{}", x + X_OFFSET - r, y + Y_OFFSET - r)
	}
	else
		Gui %hCircle%: Hide
Return

makeCircle(color, r := 400, thickness := 10, transparency := 254) {
	static HWND := MakeGui()
	d := 2 * r

	; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
	outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", d, "Int", d)
	inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int", d - thickness, "Int", d - thickness)
	DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
	DllCall("SetWindowRgn", "UInt", HWND, "UInt", outer, "UInt", true)

	Gui %HWND%:Color, % color
	Gui %HWND%:Show, xCenter yCenter w%d% h%d% NoActivate
	WinSet Transparent, % transparency, % "ahk_id " HWND

	return HWND
}

MakeGui() {
	Gui New, +E0x20 +AlwaysOnTop +ToolWindow -Caption +Hwndhwnd
	return hwnd
}

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 80 guests